Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions test/dune
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
(executables (names test_static_person test_versioned_bookmark test_postgres_static test_postgres_versioned)
(modules (:standard \ "test_utils"))
(enabled_if (= %{profile} test))
(libraries test_utils petrol caqti caqti-lwt caqti-driver-sqlite3 caqti-driver-postgresql))
(libraries test_utils petrol caqti caqti-lwt.unix caqti-driver-sqlite3 caqti-driver-postgresql))

(library (name test_utils)
(modules "test_utils")
(enabled_if (= %{profile} test))
(libraries petrol caqti caqti-lwt caqti-driver-sqlite3 caqti-driver-postgresql))
(libraries petrol caqti caqti-lwt.unix caqti-driver-sqlite3 caqti-driver-postgresql))


3 changes: 1 addition & 2 deletions test/postgres_static/dune
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
(cram (deps ../test_postgres_static.exe)
(enabled_if (= %{profile} test)))
(cram (deps ../test_postgres_static.exe))
2 changes: 1 addition & 1 deletion test/postgres_static/test-insert-duplicate.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$ ../test_postgres_static.exe testing_insert_duplicate add bob 20
$ ../test_postgres_static.exe testing_insert_duplicate add harry 10
$ ../test_postgres_static.exe testing_insert_duplicate add harry 10
Fatal error: exception Request to <postgresql://localhost:5432/testing_insert_duplicate> failed: ERROR: duplicate key value violates unique constraint "unique_names"
Fatal error: exception Request to <postgresql:///testing_insert_duplicate> failed: ERROR: duplicate key value violates unique constraint "unique_names"
DETAIL: Key (name)=(harry) already exists.
Query: "INSERT INTO person (name, age) VALUES ($1, $2)".
[2]
Expand Down
4 changes: 1 addition & 3 deletions test/postgres_versioned/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
(cram
(deps ../test_postgres_versioned.exe)
(enabled_if (= %{profile} test)))
(cram (deps ../test_postgres_versioned.exe))
3 changes: 1 addition & 2 deletions test/static/dune
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
(cram (deps ../test_static_person.exe)
(enabled_if (= %{profile} test)))
(cram (deps ../test_static_person.exe))
2 changes: 1 addition & 1 deletion test/static/test-insert-duplicate.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
$ ../test_static_person.exe add test.db harry 10
- id: 5
$ ../test_static_person.exe add test.db harry 10
Fatal error: exception Response from <sqlite3:///test.db> failed: UNIQUE constraint failed: person.name. Query: "INSERT INTO person (name, age) VALUES (?1, ?2)\nRETURNING person.id".
Fatal error: exception Request to <sqlite3:///test.db> failed: UNIQUE constraint failed: person.name (ERC#2067). Query: "INSERT INTO person (name, age) VALUES (?1, ?2)\nRETURNING person.id".
[2]
2 changes: 1 addition & 1 deletion test/test_postgres_static.ml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ let () =
Lwt.return_ok ()
| "insert-random" :: _ ->
let fname = Sys.argv.(2) in
let* conn = Caqti_lwt.connect (Uri.of_string ("sqlite3://:" ^ fname)) in
let* conn = Caqti_lwt_unix.connect (Uri.of_string ("sqlite3://:" ^ fname)) in
let* _ = Petrol.StaticSchema.initialise db conn in
let person = Person.random () in
let* _ = Person.Sql.insert person conn in
Expand Down
2 changes: 1 addition & 1 deletion test/test_static_person.ml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ let () =
Lwt.return_ok ()
| "insert-random", _ ->
let fname = Sys.argv.(2) in
let* conn = Caqti_lwt.connect (Uri.of_string ("sqlite3://:" ^ fname)) in
let* conn = Caqti_lwt_unix.connect (Uri.of_string ("sqlite3://:" ^ fname)) in
let* _ = Petrol.StaticSchema.initialise db conn in
let person = Person.random () in
let* (pid, ()) = Person.Sql.insert person conn in
Expand Down
8 changes: 4 additions & 4 deletions test/test_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let main f =
let open Lwt_result.Syntax in
let fname = Sys.argv.(2) in
run begin
let* conn = Caqti_lwt.connect (Uri.of_string ("sqlite3://:" ^ fname)) in
let* conn = Caqti_lwt_unix.connect (Uri.of_string ("sqlite3://:" ^ fname)) in
let args = List.init (Array.length Sys.argv - 3) (fun ind -> Sys.argv.(3 + ind)) in
match f conn (Sys.argv.(1), args) with
| computation ->
Expand All @@ -30,17 +30,17 @@ let main_postgres f =
let args = List.init (Array.length Sys.argv - 1) (fun ind -> Sys.argv.(1 + ind)) in
match[@warning "-8"] args with
| ["createdb"; name] ->
let* (module DB) = Caqti_lwt.connect (Uri.of_string "postgresql://localhost:5432") in
let* (module DB) = Caqti_lwt_unix.connect (Uri.of_string "postgresql://") in
Lwt.bind (DB.exec (Caqti_request.Infix.(Caqti_type.unit ->. Caqti_type.unit)
(Format.sprintf {sql| CREATE DATABASE %s |sql} name)) ()) @@
fun err -> Lwt.bind (DB.disconnect ()) @@ fun () -> Lwt.return err
| ["dropdb"; name] ->
let* (module DB) = Caqti_lwt.connect (Uri.of_string "postgresql://localhost:5432") in
let* (module DB) = Caqti_lwt_unix.connect (Uri.of_string "postgresql://") in
Lwt.bind (DB.exec (Caqti_request.Infix.(Caqti_type.unit ->. Caqti_type.unit)
(Format.sprintf {sql| DROP DATABASE IF EXISTS %s WITH (FORCE) |sql} name)) ()) @@
fun err -> Lwt.bind (DB.disconnect ()) @@ fun () -> Lwt.return err
| name :: args ->
let* ((module DB) as conn) = Caqti_lwt.connect (Uri.of_string (Format.sprintf "postgresql://localhost:5432/%s" name)) in
let* ((module DB) as conn) = Caqti_lwt_unix.connect (Uri.of_string (Format.sprintf "postgresql:///%s" name)) in
try
Lwt.bind begin match f conn args with
| computation -> computation
Expand Down
3 changes: 1 addition & 2 deletions test/versioned/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
(cram
(deps ../test_versioned_bookmark.exe)
(enabled_if (= %{profile} test)))
(deps ../test_versioned_bookmark.exe))