diff options
| author | Estevan Castilho <tevo@riajuu.net> | 2026-08-01 00:30:46 +0000 |
|---|---|---|
| committer | Estevan Castilho <tevo@riajuu.net> | 2026-08-01 00:30:46 +0000 |
| commit | a26d8bbd4dd854c17a57d38ef8d8fa0361cc5d7c (patch) | |
| tree | 41fc4e2efff3db73f65d4f9d031e113c52d472a0 | |
| parent | b60c67be7aaddb1a45a747bc6ac0402ab5d3a945 (diff) | |
| download | RNT-a26d8bbd4dd854c17a57d38ef8d8fa0361cc5d7c.tar.gz RNT-a26d8bbd4dd854c17a57d38ef8d8fa0361cc5d7c.zip | |
Move storage-related helpers to `Helpers`
| -rw-r--r-- | test/Helpers.ml | 25 | ||||
| -rw-r--r-- | test/unit/backend/Storage.ml | 27 |
2 files changed, 29 insertions, 23 deletions
diff --git a/test/Helpers.ml b/test/Helpers.ml index bf34b82..784170c 100644 --- a/test/Helpers.ml +++ b/test/Helpers.ml @@ -17,3 +17,28 @@ let condition_as_failure = function let pp_value ppf v = Format.pp_print_string ppf (Concepts.Value.to_string v) let value = Alcotest.testable pp_value Concepts.Value.equal + +module Storage = struct + module type CONFIGURATOR = sig + val configure : string -> Rnt.Concepts.Configuration.term + end + + module LMDB_Configurator : CONFIGURATOR = struct + let configure base = + let open Sexplib.Sexp in + List [Atom "lmdb"; List [Atom "path"; Atom base]; List [Atom "mode"; Atom "420"]] + |> Rnt.Concepts.Configuration.term_of_sexp + end + + module Make (S : Abstract.Storage.STORAGE) (C : CONFIGURATOR) = struct + let with_connection f dir () = + with_temporary_directory dir begin fun dir -> + begin + let open Utilities.Result in + let* conn = S.connect (C.configure dir) in + Ok (f conn) + end + |> condition_as_failure + end + end +end diff --git a/test/unit/backend/Storage.ml b/test/unit/backend/Storage.ml index 91db411..76bda8b 100644 --- a/test/unit/backend/Storage.ml +++ b/test/unit/backend/Storage.ml @@ -1,21 +1,9 @@ open Rnt -module type CONFIGURATOR = sig - val configure : string -> Rnt.Concepts.Configuration.term -end - -module Make (S : Abstract.Storage.STORAGE) (C : CONFIGURATOR) = struct +module Make (S : Abstract.Storage.STORAGE) (C : Helpers.Storage.CONFIGURATOR) = struct open Alcotest - let with_connection f () = - Helpers.with_temporary_directory "storage-test" begin fun dir -> - begin - let open Utilities.Result in - let* conn = S.connect (C.configure dir) in - Ok (f conn) - end - |> Helpers.condition_as_failure - end + module H = Helpers.Storage.Make (S) (C) let storage_and_retrieval conn = let key = Concepts.Hash.hash_of_value (Concepts.Value.String "value") in @@ -38,16 +26,9 @@ module Make (S : Abstract.Storage.STORAGE) (C : CONFIGURATOR) = struct let suite prefix = ( "storage/" ^ prefix, - [test_case "storage-and-retrieval" `Quick (with_connection storage_and_retrieval)] ) -end - -module LMDB_Configurator : CONFIGURATOR = struct - let configure base = - let open Sexplib.Sexp in - List [Atom "lmdb"; List [Atom "path"; Atom base]; List [Atom "mode"; Atom "420"]] - |> Rnt.Concepts.Configuration.term_of_sexp + [test_case "storage-and-retrieval" `Quick (H.with_connection storage_and_retrieval "storage-test")] ) end -module LMDB = Make (Rnt.Backend.Storage.LMDB) (LMDB_Configurator) +module LMDB = Make (Rnt.Backend.Storage.LMDB) (Helpers.Storage.LMDB_Configurator) let suites () = [LMDB.suite "lmdb"] |
