-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Add NAPI wrapper for create_deployment #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
897a84a
Add NAPI wrapper for create_deployment
Luke-Sanderson 9ea039b
add unit tests
Luke-Sanderson b21971f
Bump atlas-local-lib commit hash
Luke-Sanderson 87230b5
Skip windows test in CI.yml
Luke-Sanderson 0e7b5d4
Move windows check inside test
Luke-Sanderson f6868ab
Bump package.json version to create new release
Luke-Sanderson d1fcb92
Revert bump package.json
Luke-Sanderson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
use crate::models::list_deployments::{CreationSource, MongoDBPortBinding}; | ||
use napi_derive::napi; | ||
use semver::Version; | ||
|
||
#[napi(object)] | ||
pub struct CreateDeploymentOptions { | ||
// Identifiers | ||
pub name: Option<String>, | ||
|
||
// Image details | ||
pub image: Option<String>, | ||
pub mongodb_version: Option<String>, | ||
|
||
// Creation source | ||
pub creation_source: Option<CreationSource>, | ||
|
||
// Initial database configuration | ||
pub local_seed_location: Option<String>, | ||
pub mongodb_initdb_database: Option<String>, | ||
pub mongodb_initdb_root_password_file: Option<String>, | ||
pub mongodb_initdb_root_password: Option<String>, | ||
pub mongodb_initdb_root_username_file: Option<String>, | ||
pub mongodb_initdb_root_username: Option<String>, | ||
|
||
// Logging | ||
pub mongot_log_file: Option<String>, | ||
pub runner_log_file: Option<String>, | ||
|
||
// Telemetry | ||
pub do_not_track: Option<bool>, | ||
pub telemetry_base_url: Option<String>, | ||
|
||
// Port configuration | ||
pub mongodb_port_binding: Option<MongoDBPortBinding>, | ||
} | ||
|
||
impl From<CreateDeploymentOptions> for atlas_local::models::CreateDeploymentOptions { | ||
fn from(source: CreateDeploymentOptions) -> Self { | ||
let version: Option<Version> = match source.mongodb_version.as_deref() { | ||
Some("latest") => None, | ||
None => None, | ||
Some(ver_string) => { | ||
// If malformed Version if given, it will panic here | ||
Some(Version::parse(ver_string).expect("Parse version string")) | ||
} | ||
}; | ||
|
||
Self { | ||
name: source.name, | ||
image: source.image, | ||
mongodb_version: version, | ||
creation_source: source | ||
.creation_source | ||
.map(atlas_local::models::CreationSource::from), | ||
local_seed_location: source.local_seed_location, | ||
mongodb_initdb_database: source.mongodb_initdb_database, | ||
mongodb_initdb_root_password_file: source.mongodb_initdb_root_password_file, | ||
mongodb_initdb_root_password: source.mongodb_initdb_root_password, | ||
mongodb_initdb_root_username_file: source.mongodb_initdb_root_username_file, | ||
mongodb_initdb_root_username: source.mongodb_initdb_root_username, | ||
mongot_log_file: source.mongot_log_file, | ||
runner_log_file: source.runner_log_file, | ||
do_not_track: source.do_not_track, | ||
telemetry_base_url: source.telemetry_base_url, | ||
mongodb_port_binding: source | ||
.mongodb_port_binding | ||
.map(atlas_local::models::MongoDBPortBinding::from), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::models::list_deployments::{BindingType, CreationSourceType}; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_lib_create_deployment_options_from_create_deployment_options() { | ||
let create_deployment_options = CreateDeploymentOptions { | ||
name: Some("test_deployment".to_string()), | ||
image: Some("mongodb/mongodb-atlas-local".to_string()), | ||
mongodb_version: Some("8.0.0".to_string()), | ||
creation_source: Some(CreationSource { | ||
source_type: CreationSourceType::MCPServer, | ||
source: "MCPSERVER".to_string(), | ||
}), | ||
local_seed_location: Some("/host/seed-data".to_string()), | ||
mongodb_initdb_database: Some("testdb".to_string()), | ||
mongodb_initdb_root_password_file: Some("/run/secrets/password".to_string()), | ||
mongodb_initdb_root_password: Some("password123".to_string()), | ||
mongodb_initdb_root_username_file: Some("/run/secrets/username".to_string()), | ||
mongodb_initdb_root_username: Some("admin".to_string()), | ||
mongot_log_file: Some("/tmp/mongot.log".to_string()), | ||
runner_log_file: Some("/tmp/runner.log".to_string()), | ||
do_not_track: Some(false), | ||
telemetry_base_url: Some("https://telemetry.example.com".to_string()), | ||
mongodb_port_binding: Some(MongoDBPortBinding { | ||
binding_type: BindingType::Loopback, | ||
ip: "127.0.0.1".to_string(), | ||
port: 27017, | ||
}), | ||
}; | ||
let lib_create_deployment_options: atlas_local::models::CreateDeploymentOptions = | ||
create_deployment_options.into(); | ||
assert_eq!( | ||
lib_create_deployment_options.name, | ||
Some("test_deployment".to_string()) | ||
); | ||
assert_eq!( | ||
lib_create_deployment_options.image, | ||
Some("mongodb/mongodb-atlas-local".to_string()) | ||
); | ||
assert_eq!( | ||
lib_create_deployment_options.mongodb_version, | ||
Some(Version::new(8, 0, 0)) | ||
); | ||
assert_eq!( | ||
lib_create_deployment_options.creation_source, | ||
Some(atlas_local::models::CreationSource::MCPServer) | ||
); | ||
assert_eq!( | ||
lib_create_deployment_options.local_seed_location, | ||
Some("/host/seed-data".to_string()) | ||
); | ||
assert_eq!( | ||
lib_create_deployment_options.mongodb_initdb_database, | ||
Some("testdb".to_string()) | ||
); | ||
assert_eq!( | ||
lib_create_deployment_options.mongodb_initdb_root_password_file, | ||
Some("/run/secrets/password".to_string()) | ||
); | ||
assert_eq!( | ||
lib_create_deployment_options.mongodb_initdb_root_password, | ||
Some("password123".to_string()) | ||
); | ||
assert_eq!( | ||
lib_create_deployment_options.mongodb_initdb_root_username_file, | ||
Some("/run/secrets/username".to_string()) | ||
); | ||
assert_eq!( | ||
lib_create_deployment_options.mongodb_initdb_root_username, | ||
Some("admin".to_string()) | ||
); | ||
assert_eq!( | ||
lib_create_deployment_options.mongot_log_file, | ||
Some("/tmp/mongot.log".to_string()) | ||
); | ||
assert_eq!( | ||
lib_create_deployment_options.runner_log_file, | ||
Some("/tmp/runner.log".to_string()) | ||
); | ||
assert_eq!(lib_create_deployment_options.do_not_track, Some(false)); | ||
assert_eq!( | ||
lib_create_deployment_options.telemetry_base_url, | ||
Some("https://telemetry.example.com".to_string()) | ||
); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.