Skip to content

Commit b8345bd

Browse files
authored
test(alias): cover RC_HOST alias resolution (#179)
1 parent 7d0dbf8 commit b8345bd

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

crates/cli/tests/env_alias.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![cfg(not(windows))]
22

3+
use std::net::TcpListener;
34
use std::path::PathBuf;
45
use std::process::Command;
56

@@ -23,6 +24,13 @@ fn rc_binary() -> PathBuf {
2324
workspace_root.join("target/release/rc")
2425
}
2526

27+
fn unused_local_endpoint() -> String {
28+
let listener = TcpListener::bind("127.0.0.1:0").expect("bind local endpoint");
29+
let address = listener.local_addr().expect("local endpoint address");
30+
drop(listener);
31+
format!("http://{address}")
32+
}
33+
2634
#[test]
2735
fn alias_list_includes_rc_host_alias_without_credentials() {
2836
let config_dir = tempfile::tempdir().expect("create config dir");
@@ -53,3 +61,36 @@ fn alias_list_includes_rc_host_alias_without_credentials() {
5361
"https://rustfs.local:9000"
5462
);
5563
}
64+
65+
#[test]
66+
fn ls_resolves_rc_host_alias_from_environment() {
67+
let config_dir = tempfile::tempdir().expect("create config dir");
68+
let endpoint = unused_local_endpoint();
69+
let (_, endpoint_authority) = endpoint.split_once("://").expect("endpoint has scheme");
70+
let env_alias = format!("http://ACCESS_KEY:SECRET_KEY@{endpoint_authority}");
71+
72+
let output = Command::new(rc_binary())
73+
.args(["--json", "ls", "myalias"])
74+
.env("RC_CONFIG_DIR", config_dir.path())
75+
.env("RC_HOST_myalias", env_alias)
76+
.output()
77+
.expect("run rc command");
78+
79+
assert_eq!(
80+
output.status.code(),
81+
Some(3),
82+
"stderr: {}",
83+
String::from_utf8_lossy(&output.stderr)
84+
);
85+
86+
let stderr = String::from_utf8(output.stderr).expect("stderr should be UTF-8");
87+
let payload: serde_json::Value = serde_json::from_str(&stderr).expect("JSON error output");
88+
assert!(
89+
payload["error"]
90+
.as_str()
91+
.expect("error message")
92+
.contains("Failed to list buckets"),
93+
"payload: {payload}"
94+
);
95+
assert_eq!(payload["details"]["type"], "network_error");
96+
}

0 commit comments

Comments
 (0)