diff --git a/Cargo.toml b/Cargo.toml index 0348a4c..3372aca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1.0.99" -atlas-local = { git = "https://github.com/mongodb/atlas-local-lib.git", rev = "fa7cb7aa67e9169f48864a81f3b63f1cf35c81bb" } +atlas-local = { git = "https://github.com/mongodb/atlas-local-lib.git", rev = "7d8de1e2b9b865fafeb4120c765b1223d500bbc1" } bollard = "0.19.2" napi = { version = "3.0.0", features = ["async", "anyhow"] } napi-derive = "3.0.0" diff --git a/__test__/index.spec.ts b/__test__/index.spec.ts index 265d5f2..74b13a9 100644 --- a/__test__/index.spec.ts +++ b/__test__/index.spec.ts @@ -34,7 +34,12 @@ test('smoke test', async (t) => { let createDeploymentOptions = { name: "test_deployment", } - await client.createDeployment(createDeploymentOptions) + let deployment = await client.createDeployment(createDeploymentOptions) + t.is(deployment.name, createDeploymentOptions.name) + + // Get deployment + let getDeployment = await client.getDeployment(createDeploymentOptions.name) + t.is(getDeployment.name,createDeploymentOptions.name) // Count deployments after creation let after_create_deployment_count = (await client.listDeployments()).length diff --git a/index.d.ts b/index.d.ts index af104f3..854c8dc 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2,9 +2,10 @@ /* eslint-disable */ export declare class Client { static connect(): Client - createDeployment(createDeplomentOptions: CreateDeploymentOptions): Promise + createDeployment(createDeplomentOptions: CreateDeploymentOptions): Promise listDeployments(): Promise> deleteDeployment(deploymentName: string): Promise + getDeployment(deploymentName: string): Promise } export declare const enum BindingType { @@ -68,7 +69,7 @@ export interface Deployment { export interface MongoDbPortBinding { type: BindingType ip: string - port: number + port?: number } export declare const enum MongodbType { diff --git a/src/lib.rs b/src/lib.rs index 7f35f1a..dbce04d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,12 +31,13 @@ impl Client { pub async fn create_deployment( &self, create_deploment_options: crate::models::create_deployment::CreateDeploymentOptions, - ) -> Result<()> { + ) -> Result { let options: atlas_local::models::CreateDeploymentOptions = create_deploment_options.into(); self .client .create_deployment(&options) .await + .map(|d| d.into()) .context("create deployment") } @@ -58,4 +59,14 @@ impl Client { .await .context("delete deployments") } + + #[napi] + pub async fn get_deployment(&self, deployment_name: String) -> Result { + self + .client + .get_deployment(&deployment_name) + .await + .context("get deployment") + .map(|d| d.into()) + } } diff --git a/src/models/create_deployment.rs b/src/models/create_deployment.rs index 400dcd6..06044fa 100644 --- a/src/models/create_deployment.rs +++ b/src/models/create_deployment.rs @@ -107,7 +107,7 @@ mod tests { mongodb_port_binding: Some(MongoDBPortBinding { binding_type: BindingType::Loopback, ip: "127.0.0.1".to_string(), - port: 27017, + port: Some(27017), }), }; let lib_create_deployment_options: atlas_local::models::CreateDeploymentOptions = diff --git a/src/models/list_deployments.rs b/src/models/list_deployments.rs index 6f457e7..eee6cce 100644 --- a/src/models/list_deployments.rs +++ b/src/models/list_deployments.rs @@ -54,7 +54,7 @@ pub struct MongoDBPortBinding { #[napi(js_name = "type")] pub binding_type: BindingType, pub ip: String, - pub port: u16, + pub port: Option, } #[napi(string_enum)] @@ -231,7 +231,7 @@ mod tests { state: atlas_local::models::State::Running, port_bindings: Some(atlas_local::models::MongoDBPortBinding { binding_type: atlas_local::models::BindingType::Loopback, - port: 27017, + port: Some(27017), }), mongodb_type: atlas_local::models::MongodbType::Community, mongodb_version: Version::new(8, 0, 0), @@ -257,7 +257,7 @@ mod tests { let port_binding = deployment.port_bindings.unwrap(); assert_eq!(port_binding.binding_type, BindingType::Loopback); assert_eq!(port_binding.ip, "127.0.0.1"); - assert_eq!(port_binding.port, 27017); + assert_eq!(port_binding.port, Some(27017)); assert_eq!(deployment.mongodb_type, MongodbType::Community); assert_eq!(deployment.mongodb_version, "8.0.0"); assert_eq!( @@ -310,36 +310,36 @@ mod tests { fn test_mongodb_port_binding_from_lib_mongodb_port_binding_loopback() { let lib_mongodb_port_binding = atlas_local::models::MongoDBPortBinding { binding_type: atlas_local::models::BindingType::Loopback, - port: 27017, + port: Some(27017), }; let mongodb_port_binding: MongoDBPortBinding = lib_mongodb_port_binding.into(); assert_eq!(mongodb_port_binding.binding_type, BindingType::Loopback); assert_eq!(mongodb_port_binding.ip, "127.0.0.1"); - assert_eq!(mongodb_port_binding.port, 27017); + assert_eq!(mongodb_port_binding.port, Some(27017)); } #[test] fn test_mongodb_port_binding_from_lib_mongodb_port_binding_any_interface() { let lib_mongodb_port_binding = atlas_local::models::MongoDBPortBinding { binding_type: atlas_local::models::BindingType::AnyInterface, - port: 27017, + port: Some(27017), }; let mongodb_port_binding: MongoDBPortBinding = lib_mongodb_port_binding.into(); assert_eq!(mongodb_port_binding.binding_type, BindingType::AnyInterface); assert_eq!(mongodb_port_binding.ip, "0.0.0.0"); - assert_eq!(mongodb_port_binding.port, 27017); + assert_eq!(mongodb_port_binding.port, Some(27017)); } #[test] fn test_mongodb_port_binding_from_lib_mongodb_port_binding_specific() { let lib_mongodb_port_binding = atlas_local::models::MongoDBPortBinding { binding_type: atlas_local::models::BindingType::Specific("192.0.2.0".parse().unwrap()), - port: 27017, + port: Some(27017), }; let mongodb_port_binding: MongoDBPortBinding = lib_mongodb_port_binding.into(); assert_eq!(mongodb_port_binding.binding_type, BindingType::Specific); assert_eq!(mongodb_port_binding.ip, "192.0.2.0"); - assert_eq!(mongodb_port_binding.port, 27017); + assert_eq!(mongodb_port_binding.port, Some(27017)); } #[test] @@ -347,7 +347,7 @@ mod tests { let mongodb_port_binding = MongoDBPortBinding { binding_type: BindingType::Loopback, ip: "127.0.0.1".to_string(), - port: 27017, + port: Some(27017), }; let lib_mongodb_port_binding: atlas_local::models::MongoDBPortBinding = mongodb_port_binding.into(); @@ -355,7 +355,7 @@ mod tests { lib_mongodb_port_binding.binding_type, atlas_local::models::BindingType::Loopback ); - assert_eq!(lib_mongodb_port_binding.port, 27017); + assert_eq!(lib_mongodb_port_binding.port, Some(27017)); } #[test] @@ -363,7 +363,7 @@ mod tests { let mongodb_port_binding = MongoDBPortBinding { binding_type: BindingType::AnyInterface, ip: "0.0.0.0".to_string(), - port: 27017, + port: Some(27017), }; let lib_mongodb_port_binding: atlas_local::models::MongoDBPortBinding = mongodb_port_binding.into(); @@ -371,14 +371,14 @@ mod tests { lib_mongodb_port_binding.binding_type, atlas_local::models::BindingType::AnyInterface ); - assert_eq!(lib_mongodb_port_binding.port, 27017); + assert_eq!(lib_mongodb_port_binding.port, Some(27017)); } #[test] fn test_mongodb_port_binding_lib_into_mongodb_port_binding_specific() { let mongodb_port_binding = MongoDBPortBinding { binding_type: BindingType::Specific, ip: "192.0.2.0".to_string(), - port: 27017, + port: Some(27017), }; let lib_mongodb_port_binding: atlas_local::models::MongoDBPortBinding = mongodb_port_binding.into(); @@ -386,7 +386,7 @@ mod tests { lib_mongodb_port_binding.binding_type, atlas_local::models::BindingType::Specific("192.0.2.0".parse().unwrap()) ); - assert_eq!(lib_mongodb_port_binding.port, 27017); + assert_eq!(lib_mongodb_port_binding.port, Some(27017)); } #[test]