Skip to content

Commit

Permalink
Move ssl version test to a github action specific target, execute thi…
Browse files Browse the repository at this point in the history
…s target in the CI.
  • Loading branch information
toots committed Jul 15, 2023
1 parent d61df8d commit bc11626
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ jobs:
run: opam install .
- name: Build and test
if: ${{ matrix.setup.runtest }}
run: opam install -t .
run: |
opam install -t .
eval $(opam env)
dune build @github_action_tests
nix-build:
runs-on: ${{ matrix.setup.os }}
Expand Down
15 changes: 15 additions & 0 deletions tests/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
(alias
(name github_action_tests)
(deps
(alias_rec runtest)))

(library
(name util)
(modules util)
Expand All @@ -14,6 +19,16 @@
(modules ssl_comm)
(libraries ssl alcotest))

(executable
(name ssl_version)
(modules ssl_version)
(libraries ssl alcotest))

(rule
(alias github_action_tests)
(action
(run ./ssl_version.exe)))

(test
(name ssl_context)
(modules ssl_context)
Expand Down
12 changes: 0 additions & 12 deletions tests/ssl_comm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,11 @@ let test_error_queue () =
check string "Library string" "SSL routines" (Option.get err.lib);
check string "Reason string" "system lib" (Option.get err.reason)

let test_version () =
let ch = Unix.open_process_in "openssl version" in
let m, n, p =
Scanf.(bscanf (Scanning.from_channel ch)) "OpenSSL %d.%d.%d" (fun x y z ->
x, y, z)
in
Unix.close_process_in ch |> ignore;
check int "major" m Ssl.native_library_version.major;
check int "minor" n Ssl.native_library_version.minor;
check int "patch" p Ssl.native_library_version.patch

let () =
Alcotest.run
"Ssl communication"
[ ( "Communication"
, [ test_case "Test init" `Quick test_init
; test_case "Test version" `Quick test_version
; test_case "Test error queue" `Quick test_error_queue
] )
]
27 changes: 27 additions & 0 deletions tests/ssl_version.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
open Alcotest
open Ssl

let test_init () = init () |> ignore

(* This test is not super robust b/c `openssl` might not be installed or
installed but linked to a different shared libary. For this reason, this test
is only run in our internal github action CI. *)
let test_version () =
let ch = Unix.open_process_in "openssl version" in
let m, n, p =
Scanf.(bscanf (Scanning.from_channel ch)) "OpenSSL %d.%d.%d" (fun x y z ->
x, y, z)
in
Unix.close_process_in ch |> ignore;
check int "major" m Ssl.native_library_version.major;
check int "minor" n Ssl.native_library_version.minor;
check int "patch" p Ssl.native_library_version.patch

let () =
Alcotest.run
"Ssl version"
[ ( "Version"
, [ test_case "Test init" `Quick test_init
; test_case "Test version" `Quick test_version
] )
]

0 comments on commit bc11626

Please sign in to comment.