Skip to content

Commit b966193

Browse files
committed
refactor: [#227] rename test helper methods in ssh_server testing
Renamed credential methods from test_username/test_password to username/password and test_ssh_connection to verify_ssh_connection. Updated all call sites. Tests: All tests pass
1 parent e2c5828 commit b966193

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

src/testing/e2e/containers/actions/ssh_wait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl SshWaitAction {
143143
"Attempting SSH connection"
144144
);
145145

146-
match Self::test_ssh_connection(socket_addr) {
146+
match Self::verify_ssh_connection(socket_addr) {
147147
Ok(()) => {
148148
info!(
149149
socket_addr = %socket_addr,
@@ -187,7 +187,7 @@ impl SshWaitAction {
187187
///
188188
/// This approach minimizes error noise by doing the lightweight port check first,
189189
/// then only checking SSH protocol when the port is already open.
190-
fn test_ssh_connection(socket_addr: SocketAddr) -> Result<()> {
190+
fn verify_ssh_connection(socket_addr: SocketAddr) -> Result<()> {
191191
// Stage 1: Check if port is open (lightweight, no SSH errors)
192192
Self::check_port_availability(socket_addr)?;
193193

src/testing/integration/ssh_server/mock_container.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ impl MockSshServerContainer {
100100

101101
/// Get the test username configured in the container
102102
#[must_use]
103-
pub fn test_username(&self) -> &str {
103+
pub fn username(&self) -> &str {
104104
&self.config.username
105105
}
106106

107107
/// Get the test password configured in the container
108108
#[must_use]
109-
pub fn test_password(&self) -> &str {
109+
pub fn password(&self) -> &str {
110110
&self.config.password
111111
}
112112
}
@@ -120,11 +120,11 @@ impl super::SshServerContainer for MockSshServerContainer {
120120
self.host_ip
121121
}
122122

123-
fn test_username(&self) -> &str {
123+
fn username(&self) -> &str {
124124
&self.config.username
125125
}
126126

127-
fn test_password(&self) -> &str {
127+
fn password(&self) -> &str {
128128
&self.config.password
129129
}
130130
}

src/testing/integration/ssh_server/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ pub trait SshServerContainer {
5555
fn host_ip(&self) -> IpAddr;
5656

5757
/// Get the test username configured in the container
58-
fn test_username(&self) -> &str;
58+
fn username(&self) -> &str;
5959

6060
/// Get the test password configured in the container
61-
fn test_password(&self) -> &str;
61+
fn password(&self) -> &str;
6262
}
6363

6464
#[cfg(test)]
@@ -79,8 +79,8 @@ mod tests {
7979
let host_ip = ssh_container.host_ip();
8080
assert_eq!(host_ip, IpAddr::V4(Ipv4Addr::LOCALHOST));
8181

82-
assert_eq!(ssh_container.test_username(), "testuser");
83-
assert_eq!(ssh_container.test_password(), "testpass");
82+
assert_eq!(ssh_container.username(), "testuser");
83+
assert_eq!(ssh_container.password(), "testpass");
8484
}
8585
Err(e) => {
8686
panic!("Mock container should always start successfully: {e}");
@@ -101,8 +101,8 @@ mod tests {
101101
let host_ip = ssh_container.host_ip();
102102
assert_eq!(host_ip, IpAddr::V4(Ipv4Addr::LOCALHOST));
103103

104-
assert_eq!(ssh_container.test_username(), "testuser");
105-
assert_eq!(ssh_container.test_password(), "testpass");
104+
assert_eq!(ssh_container.username(), "testuser");
105+
assert_eq!(ssh_container.password(), "testpass");
106106
}
107107
Err(e) => {
108108
// Real container start might fail in CI environments without Docker
@@ -122,16 +122,16 @@ mod tests {
122122
let container: &dyn SshServerContainer = &mock;
123123
assert!(container.ssh_port() > 0);
124124
assert_eq!(container.host_ip(), IpAddr::V4(Ipv4Addr::LOCALHOST));
125-
assert_eq!(container.test_username(), "testuser");
126-
assert_eq!(container.test_password(), "testpass");
125+
assert_eq!(container.username(), "testuser");
126+
assert_eq!(container.password(), "testpass");
127127
}
128128

129129
#[tokio::test]
130130
async fn it_should_enable_generic_code() {
131131
// Helper function that works with any SshServerContainer
132132
fn verify_container<C: SshServerContainer>(container: &C) {
133133
assert!(container.ssh_port() > 0);
134-
assert_eq!(container.test_username(), "testuser");
134+
assert_eq!(container.username(), "testuser");
135135
}
136136

137137
let mock = MockSshServerContainer::start()

src/testing/integration/ssh_server/real_container.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ impl RealSshServerContainer {
143143

144144
/// Get the test username configured in the container
145145
#[must_use]
146-
pub fn test_username(&self) -> &str {
146+
pub fn username(&self) -> &str {
147147
&self.config.username
148148
}
149149

150150
/// Get the test password configured in the container
151151
#[must_use]
152-
pub fn test_password(&self) -> &str {
152+
pub fn password(&self) -> &str {
153153
&self.config.password
154154
}
155155
}
@@ -163,11 +163,11 @@ impl super::SshServerContainer for RealSshServerContainer {
163163
self.host_ip
164164
}
165165

166-
fn test_username(&self) -> &str {
166+
fn username(&self) -> &str {
167167
&self.config.username
168168
}
169169

170-
fn test_password(&self) -> &str {
170+
fn password(&self) -> &str {
171171
&self.config.password
172172
}
173173
}

tests/ssh_client/command_execution_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async fn it_should_execute_remote_command_on_real_ssh_server() {
8686
let username = output.trim();
8787
assert_eq!(
8888
username,
89-
ssh_container.test_username(),
89+
ssh_container.username(),
9090
"whoami should return the test username"
9191
);
9292
}

tests/ssh_client/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl SshTestBuilder {
7676
pub fn with_mock_container(mut self, container: &MockSshServerContainer) -> Self {
7777
self.host_ip = Some(container.host_ip());
7878
self.port = Some(container.ssh_port());
79-
self.username = Some(container.test_username().to_string());
79+
self.username = Some(container.username().to_string());
8080
self.private_key_path = Some(PathBuf::from(REAL_SSH_PRIVATE_KEY));
8181
self.public_key_path = Some(PathBuf::from(REAL_SSH_PUBLIC_KEY));
8282
self
@@ -86,7 +86,7 @@ impl SshTestBuilder {
8686
pub fn with_real_container(mut self, container: &RealSshServerContainer) -> Self {
8787
self.host_ip = Some(container.host_ip());
8888
self.port = Some(container.ssh_port());
89-
self.username = Some(container.test_username().to_string());
89+
self.username = Some(container.username().to_string());
9090
self.private_key_path = Some(PathBuf::from(REAL_SSH_PRIVATE_KEY));
9191
self.public_key_path = Some(PathBuf::from(REAL_SSH_PUBLIC_KEY));
9292
self

0 commit comments

Comments
 (0)