From 7bed03c40c73a180b87cafe5e4c97b810edbb4f5 Mon Sep 17 00:00:00 2001 From: Roman Chechyotkin <73552299+romanchechyotkin@users.noreply.github.com> Date: Sun, 25 Aug 2024 14:38:12 +0300 Subject: [PATCH] testing (#13) * testing * testing * testing * updated deps * updated deps * updated deps * updated deps * release * release * release * release --- .github/workflows/release.yml | 36 +++++++++++++++++++++++++++ .github/workflows/testing.yml | 45 ++++++++++++++++++++++++++++++++++ dune-project | 1 + nats-client.opam | 1 + {tests => test}/demo/README.md | 2 +- {tests => test}/demo/demo.ml | 0 {tests => test}/demo/dune | 0 test/sid/dune | 5 ++++ test/sid/test_sid.ml | 25 +++++++++++++++++++ 9 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/testing.yml rename {tests => test}/demo/README.md (76%) rename {tests => test}/demo/demo.ml (100%) rename {tests => test}/demo/dune (100%) create mode 100644 test/sid/dune create mode 100644 test/sid/test_sid.ml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..58caec9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,36 @@ +name: release + +on: + push: + branches: [ main ] + +jobs: + + build: + needs: [unit-test] + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + + - name: Publish + uses: ocaml/setup-ocaml@v3 + with: + ocaml-compiler: 5 + + - run: opam update && opam install opam-publish + + - run: opam publish + + diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 0000000..36fc6f4 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,45 @@ +name: testing + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +permissions: read-all + +jobs: + + unit-test: + permissions: + attestations: write + contents: read + id-token: write + + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest + ocaml-compiler: + - 5 + - 4 + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout tree + uses: actions/checkout@v4 + + - name: Set-up OCaml + uses: ocaml/setup-ocaml@v3 + with: + ocaml-compiler: ${{ matrix.ocaml-compiler }} + + - run: opam install . --deps-only --with-test + + - run: opam exec -- dune build + + - run: opam exec -- dune runtest diff --git a/dune-project b/dune-project index 4a98e2c..d6eddea 100644 --- a/dune-project +++ b/dune-project @@ -18,6 +18,7 @@ (synopsis "NATS client") (description "OCaml client for NATS, the cloud native messaging system") (depends + (alcotest :with-test) (ocaml (> 4.14)) dune diff --git a/nats-client.opam b/nats-client.opam index d248ab7..2384703 100644 --- a/nats-client.opam +++ b/nats-client.opam @@ -9,6 +9,7 @@ tags: ["nats"] homepage: "https://github.com/romanchechyotkin/nats.ocaml" bug-reports: "https://github.com/romanchechyotkin/nats.ocaml/issues" depends: [ + "alcotest" {with-test} "ocaml" {> "4.14"} "dune" {>= "3.16"} "lwt" diff --git a/tests/demo/README.md b/test/demo/README.md similarity index 76% rename from tests/demo/README.md rename to test/demo/README.md index 1f1f96c..98086ce 100644 --- a/tests/demo/README.md +++ b/test/demo/README.md @@ -3,4 +3,4 @@ ## How to run? 1. [Start NATS server](https://docs.nats.io/running-a-nats-service/nats_docker/nats-docker-tutorial) -2. Run `dune exec ./tests/demo/demo.exe` +2. Run `dune exec ./test/demo/demo.exe` diff --git a/tests/demo/demo.ml b/test/demo/demo.ml similarity index 100% rename from tests/demo/demo.ml rename to test/demo/demo.ml diff --git a/tests/demo/dune b/test/demo/dune similarity index 100% rename from tests/demo/dune rename to test/demo/dune diff --git a/test/sid/dune b/test/sid/dune new file mode 100644 index 0000000..aab07d2 --- /dev/null +++ b/test/sid/dune @@ -0,0 +1,5 @@ +(executable + (name test_sid) + (libraries nats-client alcotest) + (preprocess + (pps lwt_ppx))) diff --git a/test/sid/test_sid.ml b/test/sid/test_sid.ml new file mode 100644 index 0000000..a441044 --- /dev/null +++ b/test/sid/test_sid.ml @@ -0,0 +1,25 @@ +open Nats_client +open Alcotest + +let test_create () = + let sids = List.init 1000 (fun _ -> Sid.create 10) in + let unique_sids = List.sort_uniq String.compare sids in + + check int "same length" (List.length unique_sids) (List.length sids) + +let test_length () = + for i = 0 to 10 do + let sid = Sid.create i in + check int "same length" (String.length sid) i + done + +let () = + let open Alcotest in + run "Sid tests" + [ + ( "create", + [ + test_case "test_uniqness" `Quick test_create; + test_case "test_length" `Quick test_length; + ] ); + ]