Skip to content

Commit

Permalink
testing (#13)
Browse files Browse the repository at this point in the history
* testing

* testing

* testing

* updated deps

* updated deps

* updated deps

* updated deps

* release

* release

* release

* release
  • Loading branch information
romanchechyotkin authored Aug 25, 2024
1 parent 7abb694 commit 7bed03c
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 1 deletion.
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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


45 changes: 45 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions nats-client.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/demo/README.md → test/demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions test/sid/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(executable
(name test_sid)
(libraries nats-client alcotest)
(preprocess
(pps lwt_ppx)))
25 changes: 25 additions & 0 deletions test/sid/test_sid.ml
Original file line number Diff line number Diff line change
@@ -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;
] );
]

0 comments on commit 7bed03c

Please sign in to comment.