Skip to content

Commit a0cf976

Browse files
refactor: clean up unused imports and fix path references in tests
1 parent 1f1cb9e commit a0cf976

File tree

6 files changed

+34
-28
lines changed

6 files changed

+34
-28
lines changed

src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
730730
#[cfg(test)]
731731
mod test {
732732
use borsh::{BorshDeserialize, BorshSerialize};
733-
use solana_sdk::borsh::try_from_slice_unchecked;
734733
use solana_sdk::pubkey::Pubkey;
735734

736735
#[test]
@@ -753,4 +752,4 @@ mod test {
753752
// Assert that the deserialized data matches the original
754753
assert_eq!(faux, in_faux);
755754
}
756-
}
755+
}

src/utils/ssh_deploy/tests/unit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
mod tests {
55
use {
66
crate::utils::ssh_deploy::{
7-
errors::DeploymentError,
87
services::{create_binary_service_content, create_docker_service_content},
98
types::{AuthMethod, DeploymentConfig, NetworkType, ServerConfig},
109
validators::{
@@ -244,4 +243,4 @@ mod tests {
244243
assert!(service_content.contains("--arg1 value1"));
245244
assert!(service_content.contains("--arg2 value2"));
246245
}
247-
}
246+
}

tests/e2e/common.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Common utilities for e2e tests
22
33
use assert_cmd::prelude::*;
4-
use mockito::Server;
5-
use predicates::prelude::*;
4+
use mockito::ServerGuard;
65
use std::env;
76
use std::path::PathBuf;
87
use std::process::Command;
@@ -57,7 +56,7 @@ pub fn create_mock_config(dir: &TempDir) -> PathBuf {
5756

5857
/// Mock server for testing SSH deployment
5958
pub struct MockServer {
60-
pub server: Server,
59+
pub server: mockito::ServerGuard,
6160
}
6261

6362
impl MockServer {
@@ -74,7 +73,7 @@ impl MockServer {
7473
}
7574

7675
/// Mock an SVM list endpoint
77-
pub fn mock_svm_list(&self) -> mockito::Mock {
76+
pub fn mock_svm_list(&mut self) -> mockito::Mock {
7877
self.server.mock("GET", "/api/svms")
7978
.with_status(200)
8079
.with_header("content-type", "application/json")
@@ -83,21 +82,21 @@ impl MockServer {
8382
}
8483

8584
/// Mock an SVM get endpoint
86-
pub fn mock_svm_get(&self, svm_name: &str) -> mockito::Mock {
87-
self.server.mock("GET", &format!("/api/svms/{}", svm_name))
85+
pub fn mock_svm_get(&mut self, svm_name: &str) -> mockito::Mock {
86+
self.server.mock("GET", format!("/api/svms/{}", svm_name).as_str())
8887
.with_status(200)
8988
.with_header("content-type", "application/json")
9089
.with_body(format!(r#"{{"name":"{}","display_name":"{}","token_symbol":"TEST","token_price_usd":1.0}}"#, svm_name, svm_name.to_uppercase()))
9190
.create()
9291
}
9392

9493
/// Mock an SVM get endpoint with 404 response
95-
pub fn mock_svm_get_not_found(&self, svm_name: &str) -> mockito::Mock {
94+
pub fn mock_svm_get_not_found(&mut self, svm_name: &str) -> mockito::Mock {
9695
self.server
97-
.mock("GET", &format!("/api/svms/{}", svm_name))
96+
.mock("GET", format!("/api/svms/{}", svm_name).as_str())
9897
.with_status(404)
9998
.with_header("content-type", "application/json")
10099
.with_body(format!(r#"{{"error":"SVM not found: {}"}}"#, svm_name))
101100
.create()
102101
}
103-
}
102+
}

tests/e2e/examples.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Example tests to demonstrate how to write e2e tests
22
3-
use crate::tests::e2e::common::{
3+
use assert_cmd::assert::OutputAssertExt;
4+
use crate::e2e::common::{
45
create_mock_config, create_temp_dir, output_contains, run_osvm_command,
56
run_osvm_command_string, MockServer,
67
};
@@ -40,7 +41,7 @@ fn example_test_with_assert_cmd() {
4041
#[serial]
4142
fn example_test_with_mock_server() {
4243
// Create a mock server
43-
let mock_server = MockServer::new();
44+
let mut mock_server = MockServer::new();
4445

4546
// Set up a mock endpoint
4647
let _mock = mock_server.mock_svm_list();
@@ -73,4 +74,4 @@ fn example_test_with_custom_config() {
7374

7475
// Check if the output contains expected text
7576
assert!(output_contains(&output, "Available SVMs in the chain:"));
76-
}
77+
}

tests/e2e/node_tests.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! End-to-end tests for node-related commands
22
3-
use crate::tests::e2e::common::{
3+
use assert_cmd::assert::OutputAssertExt;
4+
use crate::e2e::common::{
45
create_mock_config, create_temp_dir, output_contains, run_osvm_command,
5-
run_osvm_command_string, MockServer,
6+
run_osvm_command_string,
67
};
78
use predicates::prelude::*;
89
use serial_test::serial;
@@ -156,4 +157,4 @@ fn test_help_command() {
156157
.stdout(predicate::str::contains("USAGE:"))
157158
.stdout(predicate::str::contains("FLAGS:"))
158159
.stdout(predicate::str::contains("SUBCOMMANDS:"));
159-
}
160+
}

tests/e2e/svm_tests.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
//! End-to-end tests for SVM-related commands
22
3-
use crate::tests::e2e::common::{output_contains, run_osvm_command, run_osvm_command_string};
3+
use assert_cmd::assert::OutputAssertExt;
4+
use crate::e2e::common::{
5+
create_mock_config, create_temp_dir, output_contains, run_osvm_command,
6+
run_osvm_command_string, MockServer,
7+
};
8+
use predicates::prelude::*;
9+
use serial_test::serial;
410

511
#[test]
612
fn test_svm_list() {
@@ -39,14 +45,15 @@ fn test_svm_get_solana() {
3945

4046
#[test]
4147
fn test_svm_get_invalid() {
42-
let output = run_osvm_command(&["svm", "get", "invalid_svm"]);
48+
// Use assert_cmd to run a command and make assertions about the output
49+
let assert = run_osvm_command()
50+
.args(&["svm", "get", "invalid_svm"])
51+
.assert();
4352

4453
// Verify the command fails with a non-zero exit code
45-
assert!(!output.status.success());
46-
47-
// Verify the error message
48-
let error = String::from_utf8_lossy(&output.stderr);
49-
assert!(error.contains("SVM not found") || error.contains("Error:"));
54+
assert
55+
.failure()
56+
.stderr(predicate::str::contains("SVM not found").or(predicate::str::contains("Error:")));
5057
}
5158

5259
#[test]
@@ -79,7 +86,7 @@ fn test_svm_with_config_file() {
7986
#[serial]
8087
fn test_svm_with_url() {
8188
// Create a mock server
82-
let mock_server = MockServer::new();
89+
let mut mock_server = MockServer::new();
8390
let _mock = mock_server.mock_svm_list();
8491

8592
// Run the command with a custom URL
@@ -92,4 +99,4 @@ fn test_svm_with_url() {
9299

93100
// Verify the output contains expected headers
94101
assert!(output_contains(&output, "Available SVMs in the chain:"));
95-
}
102+
}

0 commit comments

Comments
 (0)