Skip to content

Commit 34429c0

Browse files
Merge pull request #7 from mongodb-js/MCP-205
feat: Change createDeployment to return the deployment it created
2 parents 5587387 + ec99a14 commit 34429c0

File tree

6 files changed

+38
-21
lines changed

6 files changed

+38
-21
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ crate-type = ["cdylib"]
1010

1111
[dependencies]
1212
anyhow = "1.0.99"
13-
atlas-local = { git = "https://github.com/mongodb/atlas-local-lib.git", rev = "fa7cb7aa67e9169f48864a81f3b63f1cf35c81bb" }
13+
atlas-local = { git = "https://github.com/mongodb/atlas-local-lib.git", rev = "7d8de1e2b9b865fafeb4120c765b1223d500bbc1" }
1414
bollard = "0.19.2"
1515
napi = { version = "3.0.0", features = ["async", "anyhow"] }
1616
napi-derive = "3.0.0"

__test__/index.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ test('smoke test', async (t) => {
3434
let createDeploymentOptions = {
3535
name: "test_deployment",
3636
}
37-
await client.createDeployment(createDeploymentOptions)
37+
let deployment = await client.createDeployment(createDeploymentOptions)
38+
t.is(deployment.name, createDeploymentOptions.name)
39+
40+
// Get deployment
41+
let getDeployment = await client.getDeployment(createDeploymentOptions.name)
42+
t.is(getDeployment.name,createDeploymentOptions.name)
3843

3944
// Count deployments after creation
4045
let after_create_deployment_count = (await client.listDeployments()).length

index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
/* eslint-disable */
33
export declare class Client {
44
static connect(): Client
5-
createDeployment(createDeplomentOptions: CreateDeploymentOptions): Promise<void>
5+
createDeployment(createDeplomentOptions: CreateDeploymentOptions): Promise<Deployment>
66
listDeployments(): Promise<Array<Deployment>>
77
deleteDeployment(deploymentName: string): Promise<void>
8+
getDeployment(deploymentName: string): Promise<Deployment>
89
}
910

1011
export declare const enum BindingType {
@@ -68,7 +69,7 @@ export interface Deployment {
6869
export interface MongoDbPortBinding {
6970
type: BindingType
7071
ip: string
71-
port: number
72+
port?: number
7273
}
7374

7475
export declare const enum MongodbType {

src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ impl Client {
3131
pub async fn create_deployment(
3232
&self,
3333
create_deploment_options: crate::models::create_deployment::CreateDeploymentOptions,
34-
) -> Result<()> {
34+
) -> Result<Deployment> {
3535
let options: atlas_local::models::CreateDeploymentOptions = create_deploment_options.into();
3636
self
3737
.client
3838
.create_deployment(&options)
3939
.await
40+
.map(|d| d.into())
4041
.context("create deployment")
4142
}
4243

@@ -58,4 +59,14 @@ impl Client {
5859
.await
5960
.context("delete deployments")
6061
}
62+
63+
#[napi]
64+
pub async fn get_deployment(&self, deployment_name: String) -> Result<Deployment> {
65+
self
66+
.client
67+
.get_deployment(&deployment_name)
68+
.await
69+
.context("get deployment")
70+
.map(|d| d.into())
71+
}
6172
}

src/models/create_deployment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ mod tests {
107107
mongodb_port_binding: Some(MongoDBPortBinding {
108108
binding_type: BindingType::Loopback,
109109
ip: "127.0.0.1".to_string(),
110-
port: 27017,
110+
port: Some(27017),
111111
}),
112112
};
113113
let lib_create_deployment_options: atlas_local::models::CreateDeploymentOptions =

src/models/list_deployments.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct MongoDBPortBinding {
5454
#[napi(js_name = "type")]
5555
pub binding_type: BindingType,
5656
pub ip: String,
57-
pub port: u16,
57+
pub port: Option<u16>,
5858
}
5959

6060
#[napi(string_enum)]
@@ -231,7 +231,7 @@ mod tests {
231231
state: atlas_local::models::State::Running,
232232
port_bindings: Some(atlas_local::models::MongoDBPortBinding {
233233
binding_type: atlas_local::models::BindingType::Loopback,
234-
port: 27017,
234+
port: Some(27017),
235235
}),
236236
mongodb_type: atlas_local::models::MongodbType::Community,
237237
mongodb_version: Version::new(8, 0, 0),
@@ -257,7 +257,7 @@ mod tests {
257257
let port_binding = deployment.port_bindings.unwrap();
258258
assert_eq!(port_binding.binding_type, BindingType::Loopback);
259259
assert_eq!(port_binding.ip, "127.0.0.1");
260-
assert_eq!(port_binding.port, 27017);
260+
assert_eq!(port_binding.port, Some(27017));
261261
assert_eq!(deployment.mongodb_type, MongodbType::Community);
262262
assert_eq!(deployment.mongodb_version, "8.0.0");
263263
assert_eq!(
@@ -310,83 +310,83 @@ mod tests {
310310
fn test_mongodb_port_binding_from_lib_mongodb_port_binding_loopback() {
311311
let lib_mongodb_port_binding = atlas_local::models::MongoDBPortBinding {
312312
binding_type: atlas_local::models::BindingType::Loopback,
313-
port: 27017,
313+
port: Some(27017),
314314
};
315315
let mongodb_port_binding: MongoDBPortBinding = lib_mongodb_port_binding.into();
316316
assert_eq!(mongodb_port_binding.binding_type, BindingType::Loopback);
317317
assert_eq!(mongodb_port_binding.ip, "127.0.0.1");
318-
assert_eq!(mongodb_port_binding.port, 27017);
318+
assert_eq!(mongodb_port_binding.port, Some(27017));
319319
}
320320

321321
#[test]
322322
fn test_mongodb_port_binding_from_lib_mongodb_port_binding_any_interface() {
323323
let lib_mongodb_port_binding = atlas_local::models::MongoDBPortBinding {
324324
binding_type: atlas_local::models::BindingType::AnyInterface,
325-
port: 27017,
325+
port: Some(27017),
326326
};
327327
let mongodb_port_binding: MongoDBPortBinding = lib_mongodb_port_binding.into();
328328
assert_eq!(mongodb_port_binding.binding_type, BindingType::AnyInterface);
329329
assert_eq!(mongodb_port_binding.ip, "0.0.0.0");
330-
assert_eq!(mongodb_port_binding.port, 27017);
330+
assert_eq!(mongodb_port_binding.port, Some(27017));
331331
}
332332

333333
#[test]
334334
fn test_mongodb_port_binding_from_lib_mongodb_port_binding_specific() {
335335
let lib_mongodb_port_binding = atlas_local::models::MongoDBPortBinding {
336336
binding_type: atlas_local::models::BindingType::Specific("192.0.2.0".parse().unwrap()),
337-
port: 27017,
337+
port: Some(27017),
338338
};
339339
let mongodb_port_binding: MongoDBPortBinding = lib_mongodb_port_binding.into();
340340
assert_eq!(mongodb_port_binding.binding_type, BindingType::Specific);
341341
assert_eq!(mongodb_port_binding.ip, "192.0.2.0");
342-
assert_eq!(mongodb_port_binding.port, 27017);
342+
assert_eq!(mongodb_port_binding.port, Some(27017));
343343
}
344344

345345
#[test]
346346
fn test_mongodb_port_binding_lib_into_mongodb_port_binding_loopback() {
347347
let mongodb_port_binding = MongoDBPortBinding {
348348
binding_type: BindingType::Loopback,
349349
ip: "127.0.0.1".to_string(),
350-
port: 27017,
350+
port: Some(27017),
351351
};
352352
let lib_mongodb_port_binding: atlas_local::models::MongoDBPortBinding =
353353
mongodb_port_binding.into();
354354
assert_eq!(
355355
lib_mongodb_port_binding.binding_type,
356356
atlas_local::models::BindingType::Loopback
357357
);
358-
assert_eq!(lib_mongodb_port_binding.port, 27017);
358+
assert_eq!(lib_mongodb_port_binding.port, Some(27017));
359359
}
360360

361361
#[test]
362362
fn test_mongodb_port_binding_lib_into_mongodb_port_binding_any_interface() {
363363
let mongodb_port_binding = MongoDBPortBinding {
364364
binding_type: BindingType::AnyInterface,
365365
ip: "0.0.0.0".to_string(),
366-
port: 27017,
366+
port: Some(27017),
367367
};
368368
let lib_mongodb_port_binding: atlas_local::models::MongoDBPortBinding =
369369
mongodb_port_binding.into();
370370
assert_eq!(
371371
lib_mongodb_port_binding.binding_type,
372372
atlas_local::models::BindingType::AnyInterface
373373
);
374-
assert_eq!(lib_mongodb_port_binding.port, 27017);
374+
assert_eq!(lib_mongodb_port_binding.port, Some(27017));
375375
}
376376
#[test]
377377
fn test_mongodb_port_binding_lib_into_mongodb_port_binding_specific() {
378378
let mongodb_port_binding = MongoDBPortBinding {
379379
binding_type: BindingType::Specific,
380380
ip: "192.0.2.0".to_string(),
381-
port: 27017,
381+
port: Some(27017),
382382
};
383383
let lib_mongodb_port_binding: atlas_local::models::MongoDBPortBinding =
384384
mongodb_port_binding.into();
385385
assert_eq!(
386386
lib_mongodb_port_binding.binding_type,
387387
atlas_local::models::BindingType::Specific("192.0.2.0".parse().unwrap())
388388
);
389-
assert_eq!(lib_mongodb_port_binding.port, 27017);
389+
assert_eq!(lib_mongodb_port_binding.port, Some(27017));
390390
}
391391

392392
#[test]

0 commit comments

Comments
 (0)