mirror of
https://github.com/imjasonh/krust
synced 2026-07-08 06:45:32 +00:00
fix: Clear all Docker config paths in tests to fix CI
- Clear HOME env var to avoid ~/.docker/config.json - Clear XDG_RUNTIME_DIR to avoid containers/auth.json - Add debug output for failed auth resolution - Tests should now pass in CI environments 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
332f47b73b
commit
618525b7ed
1 changed files with 57 additions and 1 deletions
|
|
@ -15,13 +15,31 @@ fn test_resolve_auth_anonymous() -> Result<()> {
|
||||||
// Save current env vars
|
// Save current env vars
|
||||||
let old_docker_config = env::var("DOCKER_CONFIG").ok();
|
let old_docker_config = env::var("DOCKER_CONFIG").ok();
|
||||||
let old_registry_auth = env::var("REGISTRY_AUTH_FILE").ok();
|
let old_registry_auth = env::var("REGISTRY_AUTH_FILE").ok();
|
||||||
|
let old_xdg_runtime = env::var("XDG_RUNTIME_DIR").ok();
|
||||||
|
let old_home = env::var("HOME").ok();
|
||||||
|
|
||||||
// Set to empty directory
|
// Set to empty directory and clear all possible config locations
|
||||||
env::set_var("DOCKER_CONFIG", tmp_dir.path());
|
env::set_var("DOCKER_CONFIG", tmp_dir.path());
|
||||||
env::remove_var("REGISTRY_AUTH_FILE");
|
env::remove_var("REGISTRY_AUTH_FILE");
|
||||||
|
env::remove_var("XDG_RUNTIME_DIR");
|
||||||
|
// Set HOME to temp dir to avoid ~/.docker/config.json
|
||||||
|
env::set_var("HOME", tmp_dir.path());
|
||||||
|
|
||||||
// Should resolve to anonymous
|
// Should resolve to anonymous
|
||||||
let auth = resolve_auth("docker.io/library/alpine")?;
|
let auth = resolve_auth("docker.io/library/alpine")?;
|
||||||
|
|
||||||
|
// Debug output for CI
|
||||||
|
if !matches!(auth, RegistryAuth::Anonymous) {
|
||||||
|
eprintln!("Expected Anonymous auth but got: {:?}", auth);
|
||||||
|
eprintln!("DOCKER_CONFIG: {:?}", env::var("DOCKER_CONFIG"));
|
||||||
|
eprintln!("REGISTRY_AUTH_FILE: {:?}", env::var("REGISTRY_AUTH_FILE"));
|
||||||
|
eprintln!("HOME: {:?}", env::var("HOME"));
|
||||||
|
|
||||||
|
// Check if there's a Docker config in the temp dir
|
||||||
|
let config_path = tmp_dir.path().join("config.json");
|
||||||
|
eprintln!("Config exists at {:?}: {}", config_path, config_path.exists());
|
||||||
|
}
|
||||||
|
|
||||||
assert!(matches!(auth, RegistryAuth::Anonymous));
|
assert!(matches!(auth, RegistryAuth::Anonymous));
|
||||||
|
|
||||||
// Restore env vars
|
// Restore env vars
|
||||||
|
|
@ -35,6 +53,16 @@ fn test_resolve_auth_anonymous() -> Result<()> {
|
||||||
} else {
|
} else {
|
||||||
env::remove_var("REGISTRY_AUTH_FILE");
|
env::remove_var("REGISTRY_AUTH_FILE");
|
||||||
}
|
}
|
||||||
|
if let Some(val) = old_xdg_runtime {
|
||||||
|
env::set_var("XDG_RUNTIME_DIR", val);
|
||||||
|
} else {
|
||||||
|
env::remove_var("XDG_RUNTIME_DIR");
|
||||||
|
}
|
||||||
|
if let Some(val) = old_home {
|
||||||
|
env::set_var("HOME", val);
|
||||||
|
} else {
|
||||||
|
env::remove_var("HOME");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -59,10 +87,14 @@ fn test_resolve_auth_from_config() -> Result<()> {
|
||||||
// Save current env vars
|
// Save current env vars
|
||||||
let old_docker_config = env::var("DOCKER_CONFIG").ok();
|
let old_docker_config = env::var("DOCKER_CONFIG").ok();
|
||||||
let old_registry_auth = env::var("REGISTRY_AUTH_FILE").ok();
|
let old_registry_auth = env::var("REGISTRY_AUTH_FILE").ok();
|
||||||
|
let old_xdg_runtime = env::var("XDG_RUNTIME_DIR").ok();
|
||||||
|
let old_home = env::var("HOME").ok();
|
||||||
|
|
||||||
// Set our test config and clear other env vars
|
// Set our test config and clear other env vars
|
||||||
env::set_var("DOCKER_CONFIG", tmp_dir.path());
|
env::set_var("DOCKER_CONFIG", tmp_dir.path());
|
||||||
env::remove_var("REGISTRY_AUTH_FILE");
|
env::remove_var("REGISTRY_AUTH_FILE");
|
||||||
|
env::remove_var("XDG_RUNTIME_DIR");
|
||||||
|
env::set_var("HOME", tmp_dir.path());
|
||||||
|
|
||||||
// Should resolve to basic auth
|
// Should resolve to basic auth
|
||||||
let auth = resolve_auth("test.registry.io/myimage")?;
|
let auth = resolve_auth("test.registry.io/myimage")?;
|
||||||
|
|
@ -80,6 +112,16 @@ fn test_resolve_auth_from_config() -> Result<()> {
|
||||||
} else {
|
} else {
|
||||||
env::remove_var("REGISTRY_AUTH_FILE");
|
env::remove_var("REGISTRY_AUTH_FILE");
|
||||||
}
|
}
|
||||||
|
if let Some(val) = old_xdg_runtime {
|
||||||
|
env::set_var("XDG_RUNTIME_DIR", val);
|
||||||
|
} else {
|
||||||
|
env::remove_var("XDG_RUNTIME_DIR");
|
||||||
|
}
|
||||||
|
if let Some(val) = old_home {
|
||||||
|
env::set_var("HOME", val);
|
||||||
|
} else {
|
||||||
|
env::remove_var("HOME");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -103,10 +145,14 @@ fn test_resolve_auth_bearer_token() -> Result<()> {
|
||||||
// Save current env vars
|
// Save current env vars
|
||||||
let old_docker_config = env::var("DOCKER_CONFIG").ok();
|
let old_docker_config = env::var("DOCKER_CONFIG").ok();
|
||||||
let old_registry_auth = env::var("REGISTRY_AUTH_FILE").ok();
|
let old_registry_auth = env::var("REGISTRY_AUTH_FILE").ok();
|
||||||
|
let old_xdg_runtime = env::var("XDG_RUNTIME_DIR").ok();
|
||||||
|
let old_home = env::var("HOME").ok();
|
||||||
|
|
||||||
// Set our test config and clear other env vars
|
// Set our test config and clear other env vars
|
||||||
env::set_var("DOCKER_CONFIG", tmp_dir.path());
|
env::set_var("DOCKER_CONFIG", tmp_dir.path());
|
||||||
env::remove_var("REGISTRY_AUTH_FILE");
|
env::remove_var("REGISTRY_AUTH_FILE");
|
||||||
|
env::remove_var("XDG_RUNTIME_DIR");
|
||||||
|
env::set_var("HOME", tmp_dir.path());
|
||||||
|
|
||||||
// Should resolve to bearer auth
|
// Should resolve to bearer auth
|
||||||
let auth = resolve_auth("ghcr.io/user/image")?;
|
let auth = resolve_auth("ghcr.io/user/image")?;
|
||||||
|
|
@ -124,6 +170,16 @@ fn test_resolve_auth_bearer_token() -> Result<()> {
|
||||||
} else {
|
} else {
|
||||||
env::remove_var("REGISTRY_AUTH_FILE");
|
env::remove_var("REGISTRY_AUTH_FILE");
|
||||||
}
|
}
|
||||||
|
if let Some(val) = old_xdg_runtime {
|
||||||
|
env::set_var("XDG_RUNTIME_DIR", val);
|
||||||
|
} else {
|
||||||
|
env::remove_var("XDG_RUNTIME_DIR");
|
||||||
|
}
|
||||||
|
if let Some(val) = old_home {
|
||||||
|
env::set_var("HOME", val);
|
||||||
|
} else {
|
||||||
|
env::remove_var("HOME");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue