@@ -37,6 +37,7 @@ pub struct Deployment {
37
37
}
38
38
39
39
#[ napi( string_enum) ]
40
+ #[ derive( PartialEq , Debug ) ]
40
41
pub enum State {
41
42
Created ,
42
43
Dead ,
@@ -48,6 +49,7 @@ pub enum State {
48
49
}
49
50
50
51
#[ napi( object) ]
52
+ #[ derive( PartialEq , Debug ) ]
51
53
pub struct MongoDBPortBinding {
52
54
#[ napi( js_name = "type" ) ]
53
55
pub binding_type : BindingType ,
@@ -56,26 +58,30 @@ pub struct MongoDBPortBinding {
56
58
}
57
59
58
60
#[ napi( string_enum) ]
61
+ #[ derive( PartialEq , Debug ) ]
59
62
pub enum BindingType {
60
63
Loopback , // 127.0.0.1
61
64
AnyInterface , // 0.0.0.0
62
65
Specific , // Specific IP address
63
66
}
64
67
65
68
#[ napi( string_enum) ]
69
+ #[ derive( PartialEq , Debug ) ]
66
70
pub enum MongodbType {
67
71
Community ,
68
72
Enterprise ,
69
73
}
70
74
71
75
#[ napi( object) ]
76
+ #[ derive( PartialEq , Debug ) ]
72
77
pub struct CreationSource {
73
78
#[ napi( js_name = "type" ) ]
74
79
pub source_type : CreationSourceType ,
75
80
pub source : String ,
76
81
}
77
82
78
83
#[ napi( string_enum) ]
84
+ #[ derive( PartialEq , Debug ) ]
79
85
pub enum CreationSourceType {
80
86
AtlasCLI ,
81
87
Container ,
@@ -210,3 +216,208 @@ impl From<CreationSource> for atlas_local::models::CreationSource {
210
216
}
211
217
}
212
218
}
219
+
220
+ #[ cfg( test) ]
221
+ mod tests {
222
+ use semver:: Version ;
223
+
224
+ use super :: * ;
225
+
226
+ #[ test]
227
+ fn test_deployment_from_lib_deployment ( ) {
228
+ let lib_deployment = atlas_local:: models:: Deployment {
229
+ container_id : "container_id" . to_string ( ) ,
230
+ name : Some ( "test_deployment" . to_string ( ) ) ,
231
+ state : atlas_local:: models:: State :: Running ,
232
+ port_bindings : Some ( atlas_local:: models:: MongoDBPortBinding {
233
+ binding_type : atlas_local:: models:: BindingType :: Loopback ,
234
+ port : 27017 ,
235
+ } ) ,
236
+ mongodb_type : atlas_local:: models:: MongodbType :: Community ,
237
+ mongodb_version : Version :: new ( 8 , 0 , 0 ) ,
238
+ creation_source : Some ( atlas_local:: models:: CreationSource :: AtlasCLI ) ,
239
+ local_seed_location : Some ( "/host/seed-data" . to_string ( ) ) ,
240
+ mongodb_initdb_database : Some ( "testdb" . to_string ( ) ) ,
241
+ mongodb_initdb_root_password_file : Some ( "/run/secrets/password" . to_string ( ) ) ,
242
+ mongodb_initdb_root_password : Some ( "password123" . to_string ( ) ) ,
243
+ mongodb_initdb_root_username_file : Some ( "/run/secrets/username" . to_string ( ) ) ,
244
+ mongodb_initdb_root_username : Some ( "admin" . to_string ( ) ) ,
245
+ mongot_log_file : Some ( "/tmp/mongot.log" . to_string ( ) ) ,
246
+ runner_log_file : Some ( "/tmp/runner.log" . to_string ( ) ) ,
247
+ do_not_track : Some ( "false" . to_string ( ) ) ,
248
+ telemetry_base_url : Some ( "https://telemetry.example.com" . to_string ( ) ) ,
249
+ } ;
250
+
251
+ let deployment: Deployment = lib_deployment. into ( ) ;
252
+
253
+ assert_eq ! ( deployment. container_id, "container_id" ) ;
254
+ assert_eq ! ( deployment. name, Some ( "test_deployment" . to_string( ) ) ) ;
255
+ assert_eq ! ( deployment. state, State :: Running ) ;
256
+ assert ! ( deployment. port_bindings. is_some( ) ) ;
257
+ let port_binding = deployment. port_bindings . unwrap ( ) ;
258
+ assert_eq ! ( port_binding. binding_type, BindingType :: Loopback ) ;
259
+ assert_eq ! ( port_binding. ip, "127.0.0.1" ) ;
260
+ assert_eq ! ( port_binding. port, 27017 ) ;
261
+ assert_eq ! ( deployment. mongodb_type, MongodbType :: Community ) ;
262
+ assert_eq ! ( deployment. mongodb_version, "8.0.0" ) ;
263
+ assert_eq ! (
264
+ deployment. creation_source,
265
+ Some ( CreationSource {
266
+ source_type: CreationSourceType :: AtlasCLI ,
267
+ source: "ATLASCLI" . to_string( ) ,
268
+ } )
269
+ ) ;
270
+ assert_eq ! (
271
+ deployment. local_seed_location,
272
+ Some ( "/host/seed-data" . to_string( ) )
273
+ ) ;
274
+ assert_eq ! (
275
+ deployment. mongodb_initdb_database,
276
+ Some ( "testdb" . to_string( ) )
277
+ ) ;
278
+ assert_eq ! (
279
+ deployment. mongodb_initdb_root_password_file,
280
+ Some ( "/run/secrets/password" . to_string( ) )
281
+ ) ;
282
+ assert_eq ! (
283
+ deployment. mongodb_initdb_root_password,
284
+ Some ( "password123" . to_string( ) )
285
+ ) ;
286
+ assert_eq ! (
287
+ deployment. mongodb_initdb_root_username_file,
288
+ Some ( "/run/secrets/username" . to_string( ) )
289
+ ) ;
290
+ assert_eq ! (
291
+ deployment. mongodb_initdb_root_username,
292
+ Some ( "admin" . to_string( ) )
293
+ ) ;
294
+ assert_eq ! (
295
+ deployment. mongot_log_file,
296
+ Some ( "/tmp/mongot.log" . to_string( ) )
297
+ ) ;
298
+ assert_eq ! (
299
+ deployment. runner_log_file,
300
+ Some ( "/tmp/runner.log" . to_string( ) )
301
+ ) ;
302
+ assert_eq ! ( deployment. do_not_track, Some ( "false" . to_string( ) ) ) ;
303
+ assert_eq ! (
304
+ deployment. telemetry_base_url,
305
+ Some ( "https://telemetry.example.com" . to_string( ) )
306
+ ) ;
307
+ }
308
+
309
+ #[ test]
310
+ fn test_mongodb_port_binding_from_lib_mongodb_port_binding_loopback ( ) {
311
+ let lib_mongodb_port_binding = atlas_local:: models:: MongoDBPortBinding {
312
+ binding_type : atlas_local:: models:: BindingType :: Loopback ,
313
+ port : 27017 ,
314
+ } ;
315
+ let mongodb_port_binding: MongoDBPortBinding = lib_mongodb_port_binding. into ( ) ;
316
+ assert_eq ! ( mongodb_port_binding. binding_type, BindingType :: Loopback ) ;
317
+ assert_eq ! ( mongodb_port_binding. ip, "127.0.0.1" ) ;
318
+ assert_eq ! ( mongodb_port_binding. port, 27017 ) ;
319
+ }
320
+
321
+ #[ test]
322
+ fn test_mongodb_port_binding_from_lib_mongodb_port_binding_any_interface ( ) {
323
+ let lib_mongodb_port_binding = atlas_local:: models:: MongoDBPortBinding {
324
+ binding_type : atlas_local:: models:: BindingType :: AnyInterface ,
325
+ port : 27017 ,
326
+ } ;
327
+ let mongodb_port_binding: MongoDBPortBinding = lib_mongodb_port_binding. into ( ) ;
328
+ assert_eq ! ( mongodb_port_binding. binding_type, BindingType :: AnyInterface ) ;
329
+ assert_eq ! ( mongodb_port_binding. ip, "0.0.0.0" ) ;
330
+ assert_eq ! ( mongodb_port_binding. port, 27017 ) ;
331
+ }
332
+
333
+ #[ test]
334
+ fn test_mongodb_port_binding_from_lib_mongodb_port_binding_specific ( ) {
335
+ let lib_mongodb_port_binding = atlas_local:: models:: MongoDBPortBinding {
336
+ binding_type : atlas_local:: models:: BindingType :: Specific ( "192.0.2.0" . parse ( ) . unwrap ( ) ) ,
337
+ port : 27017 ,
338
+ } ;
339
+ let mongodb_port_binding: MongoDBPortBinding = lib_mongodb_port_binding. into ( ) ;
340
+ assert_eq ! ( mongodb_port_binding. binding_type, BindingType :: Specific ) ;
341
+ assert_eq ! ( mongodb_port_binding. ip, "192.0.2.0" ) ;
342
+ assert_eq ! ( mongodb_port_binding. port, 27017 ) ;
343
+ }
344
+
345
+ #[ test]
346
+ fn test_mongodb_port_binding_lib_into_mongodb_port_binding_loopback ( ) {
347
+ let mongodb_port_binding = MongoDBPortBinding {
348
+ binding_type : BindingType :: Loopback ,
349
+ ip : "127.0.0.1" . to_string ( ) ,
350
+ port : 27017 ,
351
+ } ;
352
+ let lib_mongodb_port_binding: atlas_local:: models:: MongoDBPortBinding =
353
+ mongodb_port_binding. into ( ) ;
354
+ assert_eq ! (
355
+ lib_mongodb_port_binding. binding_type,
356
+ atlas_local:: models:: BindingType :: Loopback
357
+ ) ;
358
+ assert_eq ! ( lib_mongodb_port_binding. port, 27017 ) ;
359
+ }
360
+
361
+ #[ test]
362
+ fn test_mongodb_port_binding_lib_into_mongodb_port_binding_any_interface ( ) {
363
+ let mongodb_port_binding = MongoDBPortBinding {
364
+ binding_type : BindingType :: AnyInterface ,
365
+ ip : "0.0.0.0" . to_string ( ) ,
366
+ port : 27017 ,
367
+ } ;
368
+ let lib_mongodb_port_binding: atlas_local:: models:: MongoDBPortBinding =
369
+ mongodb_port_binding. into ( ) ;
370
+ assert_eq ! (
371
+ lib_mongodb_port_binding. binding_type,
372
+ atlas_local:: models:: BindingType :: AnyInterface
373
+ ) ;
374
+ assert_eq ! ( lib_mongodb_port_binding. port, 27017 ) ;
375
+ }
376
+ #[ test]
377
+ fn test_mongodb_port_binding_lib_into_mongodb_port_binding_specific ( ) {
378
+ let mongodb_port_binding = MongoDBPortBinding {
379
+ binding_type : BindingType :: Specific ,
380
+ ip : "192.0.2.0" . to_string ( ) ,
381
+ port : 27017 ,
382
+ } ;
383
+ let lib_mongodb_port_binding: atlas_local:: models:: MongoDBPortBinding =
384
+ mongodb_port_binding. into ( ) ;
385
+ assert_eq ! (
386
+ lib_mongodb_port_binding. binding_type,
387
+ atlas_local:: models:: BindingType :: Specific ( "192.0.2.0" . parse( ) . unwrap( ) )
388
+ ) ;
389
+ assert_eq ! ( lib_mongodb_port_binding. port, 27017 ) ;
390
+ }
391
+
392
+ #[ test]
393
+ fn test_creation_source_from_lib_creation_source_atlas_cli ( ) {
394
+ let lib_creation_source = atlas_local:: models:: CreationSource :: AtlasCLI ;
395
+ let creation_source: CreationSource = lib_creation_source. into ( ) ;
396
+ assert_eq ! ( creation_source. source_type, CreationSourceType :: AtlasCLI ) ;
397
+ assert_eq ! ( creation_source. source, "ATLASCLI" ) ;
398
+ }
399
+
400
+ #[ test]
401
+ fn test_creation_source_from_lib_creation_source_container ( ) {
402
+ let lib_creation_source = atlas_local:: models:: CreationSource :: Container ;
403
+ let creation_source: CreationSource = lib_creation_source. into ( ) ;
404
+ assert_eq ! ( creation_source. source_type, CreationSourceType :: Container ) ;
405
+ assert_eq ! ( creation_source. source, "CONTAINER" ) ;
406
+ }
407
+
408
+ #[ test]
409
+ fn test_creation_source_from_lib_creation_source_mcp_server ( ) {
410
+ let lib_creation_source = atlas_local:: models:: CreationSource :: MCPServer ;
411
+ let creation_source: CreationSource = lib_creation_source. into ( ) ;
412
+ assert_eq ! ( creation_source. source_type, CreationSourceType :: MCPServer ) ;
413
+ assert_eq ! ( creation_source. source, "MCPSERVER" ) ;
414
+ }
415
+
416
+ #[ test]
417
+ fn test_creation_source_from_lib_creation_source_unknown ( ) {
418
+ let lib_creation_source = atlas_local:: models:: CreationSource :: Unknown ( "test" . to_string ( ) ) ;
419
+ let creation_source: CreationSource = lib_creation_source. into ( ) ;
420
+ assert_eq ! ( creation_source. source_type, CreationSourceType :: Other ) ;
421
+ assert_eq ! ( creation_source. source, "test" ) ;
422
+ }
423
+ }
0 commit comments