Skip to content
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

Introduce a CLI tool for deploying projects #10

Merged
merged 10 commits into from
Jan 28, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add tests for deploy
katiemckeon committed Jan 28, 2025
commit 5ce5a50dd14d64aab6ad66111d9a4e0cb21aed56
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ sindri-rs = { path = "../sindri-rs"}
assert_cmd = "2.0.16"
predicates = "3.1.3"
tokio = { version = "1.0", features = ["full"] }
wiremock = "0.6.2"

[features]
default = []
37 changes: 37 additions & 0 deletions cli/src/bin/cargo-sindri.rs
Original file line number Diff line number Diff line change
@@ -99,3 +99,40 @@ fn main() {
}
}
}

#[cfg(test)]
mod tests {
use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::process::Command;

use wiremock::{
matchers::{method, path},
ResponseTemplate,
};

#[tokio::test]
async fn test_cli_deploy_unauthorized() {
let mock_server = wiremock::MockServer::start().await;

// Setup mock responses
wiremock::Mock::given(method("POST"))
.and(path("/api/v1/circuit/create"))
.respond_with(ResponseTemplate::new(401))
.mount(&mock_server)
.await;

let mut cmd = Command::cargo_bin("cargo-sindri").unwrap();

let circuit_path = "tests/factory/circuit.tar.gz";

cmd.env("SINDRI_API_KEY", "invalid");
cmd.arg("sindri").arg("deploy").arg(circuit_path).arg("--tags").arg("failure");
cmd.assert()
.failure()
.stderr(predicate::str::contains("Unauthorized"));

}


}
29 changes: 1 addition & 28 deletions cli/tests/cli.rs
Original file line number Diff line number Diff line change
@@ -2,44 +2,17 @@ use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::process::Command;

use sindri_rs::client::SindriClient;

#[tokio::test]
async fn test_cli_deploy() -> Result<(), Box<dyn std::error::Error>> {
// First build the cargo-sindri binary
let mut cmd = Command::cargo_bin("cargo-sindri")?;

let circuit_path = "tests/factory/circuit.tar.gz";

cmd.arg("sindri").arg("deploy").arg(circuit_path);
cmd.arg("sindri").arg("deploy").arg(circuit_path).arg("--tags").arg("success");
cmd.assert()
.success()
.stdout(predicate::str::contains("Circuit created successfully!"));

// Get the circuit UUID from the output
let output = cmd.output()?;
let stdout = String::from_utf8_lossy(&output.stdout);
let uuid = stdout.lines().find(|line| line.contains("the circuit UUID")).unwrap().split("UUID: ").nth(1).unwrap();

// Cleanup: Delete the circuit via the UUID
let client = SindriClient::new(None, None);
client.delete_circuit(uuid).await?;

Ok(())
}

#[tokio::test]
async fn test_cli_deploy_unauthorized() -> Result<(), Box<dyn std::error::Error>> {
// First build the cargo-sindri binary
let mut cmd = Command::cargo_bin("cargo-sindri")?;

let circuit_path = "tests/factory/circuit.tar.gz";

cmd.env("SINDRI_API_KEY", "invalid");
cmd.arg("sindri").arg("deploy").arg(circuit_path);
cmd.assert()
.failure()
.stderr(predicate::str::contains("Unauthorized"));

Ok(())
}