mirror of
https://github.com/imjasonh/krust
synced 2026-07-07 22:35:25 +00:00
fix: Fix test environment variable pollution and formatting
- Clear REGISTRY_AUTH_FILE in all credential helper tests to avoid conflicts - Apply rustfmt formatting - Tests pass reliably when run sequentially (cargo test -- --test-threads=1) - Note: Tests may fail when run in parallel due to env var mutations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
672ada3dd2
commit
332f47b73b
1 changed files with 14 additions and 5 deletions
|
|
@ -56,21 +56,30 @@ fn test_resolve_auth_from_config() -> Result<()> {
|
|||
|
||||
fs::write(&config_path, config)?;
|
||||
|
||||
// Save current env var
|
||||
let old_val = env::var("DOCKER_CONFIG").ok();
|
||||
// Save current env vars
|
||||
let old_docker_config = env::var("DOCKER_CONFIG").ok();
|
||||
let old_registry_auth = env::var("REGISTRY_AUTH_FILE").ok();
|
||||
|
||||
// Set our test config and clear other env vars
|
||||
env::set_var("DOCKER_CONFIG", tmp_dir.path());
|
||||
env::remove_var("REGISTRY_AUTH_FILE");
|
||||
|
||||
// Should resolve to basic auth
|
||||
let auth = resolve_auth("test.registry.io/myimage")?;
|
||||
assert!(matches!(auth, RegistryAuth::Basic(user, pass)
|
||||
if user == "testuser" && pass == "testpass"));
|
||||
|
||||
// Restore env var
|
||||
if let Some(val) = old_val {
|
||||
// Restore env vars
|
||||
if let Some(val) = old_docker_config {
|
||||
env::set_var("DOCKER_CONFIG", val);
|
||||
} else {
|
||||
env::remove_var("DOCKER_CONFIG");
|
||||
}
|
||||
if let Some(val) = old_registry_auth {
|
||||
env::set_var("REGISTRY_AUTH_FILE", val);
|
||||
} else {
|
||||
env::remove_var("REGISTRY_AUTH_FILE");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -94,7 +103,7 @@ fn test_resolve_auth_bearer_token() -> Result<()> {
|
|||
// Save current env vars
|
||||
let old_docker_config = env::var("DOCKER_CONFIG").ok();
|
||||
let old_registry_auth = env::var("REGISTRY_AUTH_FILE").ok();
|
||||
|
||||
|
||||
// Set our test config and clear other env vars
|
||||
env::set_var("DOCKER_CONFIG", tmp_dir.path());
|
||||
env::remove_var("REGISTRY_AUTH_FILE");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue