@@ -7,14 +7,29 @@ use eventually::{serde, version};
77use eventually_postgres:: event;
88use futures:: TryStreamExt ;
99use rand:: Rng ;
10+ use testcontainers_modules:: postgres:: Postgres ;
11+ use testcontainers_modules:: testcontainers:: runners:: AsyncRunner ;
1012
1113mod setup;
1214
1315#[ tokio:: test]
1416async fn append_with_no_version_check_works ( ) {
15- let pool = setup:: connect_to_database ( )
17+ let container = Postgres :: default ( )
18+ . start ( )
1619 . 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" ) ;
1833
1934 let event_store = event:: Store :: new ( pool, serde:: Json :: < setup:: TestDomainEvent > :: default ( ) )
2035 . await
@@ -68,9 +83,22 @@ async fn append_with_no_version_check_works() {
6883
6984#[ tokio:: test]
7085async fn it_works_with_version_check_for_conflict ( ) {
71- let pool = setup:: connect_to_database ( )
86+ let container = Postgres :: default ( )
87+ . start ( )
7288 . 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" ) ;
74102
75103 let event_store = event:: Store :: new ( pool, serde:: Json :: < setup:: TestDomainEvent > :: default ( ) )
76104 . await
@@ -143,9 +171,22 @@ async fn it_works_with_version_check_for_conflict() {
143171
144172#[ tokio:: test]
145173async fn it_handles_concurrent_writes_to_the_same_stream ( ) {
146- let pool = setup:: connect_to_database ( )
174+ let container = Postgres :: default ( )
175+ . start ( )
147176 . 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" ) ;
149190
150191 let event_store = event:: Store :: new ( pool, serde:: Json :: < setup:: TestDomainEvent > :: default ( ) )
151192 . await
0 commit comments