11use std:: convert:: Infallible ;
22
33use hyper:: { service:: make_service_fn, Response , Body , StatusCode } ;
4+ use insta:: assert_snapshot;
45use libsql:: { Database , Value } ;
56use serde_json:: json;
67use tempfile:: tempdir;
@@ -157,9 +158,10 @@ fn load_namespace_from_no_txn() {
157158
158159 sim. client ( "client" , async move {
159160 let client = Client :: new ( ) ;
160- let resp = client. post ( "http://primary:9090/v1/namespaces/foo/create" , json ! ( { "dump_url" : format!( "file:{}" , tmp_path. join( "dump.sql" ) . display( ) ) } ) ) . await . unwrap ( ) ;
161+ let resp = client. post ( "http://primary:9090/v1/namespaces/foo/create" , json ! ( { "dump_url" : format!( "file:{}" , tmp_path. join( "dump.sql" ) . display( ) ) } ) ) . await ? ;
161162 // the dump is malformed
162163 assert_eq ! ( resp. status( ) , StatusCode :: BAD_REQUEST , "{}" , resp. json:: <serde_json:: Value >( ) . await . unwrap_or_default( ) ) ;
164+ assert_snapshot ! ( resp. json_value( ) . await . unwrap( ) ) ;
163165
164166 // namespace doesn't exist
165167 let foo = Database :: open_remote_with_connector ( "http://foo.primary:8080" , "" , TurmoilConnector ) ?;
@@ -171,3 +173,34 @@ fn load_namespace_from_no_txn() {
171173
172174 sim. run ( ) . unwrap ( ) ;
173175}
176+
177+ #[ test]
178+ fn export_dump ( ) {
179+ let mut sim = Builder :: new ( ) . build ( ) ;
180+ let tmp = tempdir ( ) . unwrap ( ) ;
181+
182+ make_primary ( & mut sim, tmp. path ( ) . to_path_buf ( ) ) ;
183+
184+ sim. client ( "client" , async move {
185+ let client = Client :: new ( ) ;
186+ let resp = client. post ( "http://primary:9090/v1/namespaces/foo/create" , json ! ( { } ) ) . await ?;
187+ assert_eq ! ( resp. status( ) , StatusCode :: OK ) ;
188+ assert_snapshot ! ( resp. json_value( ) . await . unwrap( ) ) ;
189+
190+ let foo = Database :: open_remote_with_connector ( "http://foo.primary:8080" , "" , TurmoilConnector ) ?;
191+ let foo_conn = foo. connect ( ) ?;
192+ foo_conn. execute ( "create table test (x)" , ( ) ) . await ?;
193+ foo_conn. execute ( "insert into test values (42)" , ( ) ) . await ?;
194+ foo_conn. execute ( "insert into test values (\" foo\" )" , ( ) ) . await ?;
195+ foo_conn. execute ( "insert into test values (\" bar\" )" , ( ) ) . await ?;
196+
197+
198+ let resp = client. get ( "http://foo.primary:8080/dump" ) . await ?;
199+ assert_eq ! ( resp. status( ) , StatusCode :: OK ) ;
200+ assert_snapshot ! ( resp. body_string( ) . await ?) ;
201+
202+ Ok ( ( ) )
203+ } ) ;
204+
205+ sim. run ( ) . unwrap ( ) ;
206+ }
0 commit comments