@@ -7,14 +7,29 @@ use eventually::{serde, version};
7
7
use eventually_postgres:: event;
8
8
use futures:: TryStreamExt ;
9
9
use rand:: Rng ;
10
+ use testcontainers_modules:: postgres:: Postgres ;
11
+ use testcontainers_modules:: testcontainers:: runners:: AsyncRunner ;
10
12
11
13
mod setup;
12
14
13
15
#[ tokio:: test]
14
16
async fn append_with_no_version_check_works ( ) {
15
- let pool = setup:: connect_to_database ( )
17
+ let container = Postgres :: default ( )
18
+ . start ( )
16
19
. await
17
- . expect ( "connection to the database should work" ) ;
20
+ . expect ( "the postgres container should start" ) ;
21
+
22
+ let ( host, port) = futures:: try_join!( container. get_host( ) , container. get_host_port_ipv4( 5432 ) )
23
+ . expect ( "the postgres container should have both a host and a port exposed" ) ;
24
+
25
+ println ! ( "postgres container is running at {host}:{port}" ) ;
26
+
27
+ let pool = sqlx:: PgPool :: connect ( & format ! (
28
+ "postgres://postgres:postgres@{}:{}/postgres" ,
29
+ host, port,
30
+ ) )
31
+ . await
32
+ . expect ( "should be able to create a connection with the database" ) ;
18
33
19
34
let event_store = event:: Store :: new ( pool, serde:: Json :: < setup:: TestDomainEvent > :: default ( ) )
20
35
. await
@@ -68,9 +83,22 @@ async fn append_with_no_version_check_works() {
68
83
69
84
#[ tokio:: test]
70
85
async fn it_works_with_version_check_for_conflict ( ) {
71
- let pool = setup:: connect_to_database ( )
86
+ let container = Postgres :: default ( )
87
+ . start ( )
72
88
. await
73
- . expect ( "connection to the database should work" ) ;
89
+ . expect ( "the postgres container should start" ) ;
90
+
91
+ let ( host, port) = futures:: try_join!( container. get_host( ) , container. get_host_port_ipv4( 5432 ) )
92
+ . expect ( "the postgres container should have both a host and a port exposed" ) ;
93
+
94
+ println ! ( "postgres container is running at {host}:{port}" ) ;
95
+
96
+ let pool = sqlx:: PgPool :: connect ( & format ! (
97
+ "postgres://postgres:postgres@{}:{}/postgres" ,
98
+ host, port,
99
+ ) )
100
+ . await
101
+ . expect ( "should be able to create a connection with the database" ) ;
74
102
75
103
let event_store = event:: Store :: new ( pool, serde:: Json :: < setup:: TestDomainEvent > :: default ( ) )
76
104
. await
@@ -143,9 +171,22 @@ async fn it_works_with_version_check_for_conflict() {
143
171
144
172
#[ tokio:: test]
145
173
async fn it_handles_concurrent_writes_to_the_same_stream ( ) {
146
- let pool = setup:: connect_to_database ( )
174
+ let container = Postgres :: default ( )
175
+ . start ( )
147
176
. await
148
- . expect ( "connection to the database should work" ) ;
177
+ . expect ( "the postgres container should start" ) ;
178
+
179
+ let ( host, port) = futures:: try_join!( container. get_host( ) , container. get_host_port_ipv4( 5432 ) )
180
+ . expect ( "the postgres container should have both a host and a port exposed" ) ;
181
+
182
+ println ! ( "postgres container is running at {host}:{port}" ) ;
183
+
184
+ let pool = sqlx:: PgPool :: connect ( & format ! (
185
+ "postgres://postgres:postgres@{}:{}/postgres" ,
186
+ host, port,
187
+ ) )
188
+ . await
189
+ . expect ( "should be able to create a connection with the database" ) ;
149
190
150
191
let event_store = event:: Store :: new ( pool, serde:: Json :: < setup:: TestDomainEvent > :: default ( ) )
151
192
. await
0 commit comments