fix: handle ComponentNamespace in CI test environment (#1387)

The TestNewAgentOptions test was failing in CI because it expected
ComponentNamespace to always be "open-cluster-management-agent", but
NewAgentOptions() reads from /var/run/secrets/kubernetes.io/serviceaccount/namespace
when running in a Kubernetes pod (which exists in CI environment).

Updated the test to accept either the default value (when running locally)
or the actual pod namespace (when running in CI), while ensuring the
namespace is never empty.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: zhujian <jiazhu@redhat.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Jian Zhu
2026-02-12 22:14:59 +08:00
committed by GitHub
parent 008b066a35
commit 2128dfebcc

View File

@@ -13,8 +13,17 @@ func TestNewAgentOptions(t *testing.T) {
if opts.HubKubeconfigDir != "/spoke/hub-kubeconfig" {
t.Errorf("unexpected HubKubeconfigDir: %s", opts.HubKubeconfigDir)
}
if opts.ComponentNamespace != "open-cluster-management-agent" {
t.Errorf("unexpected ComponentNamespace: %s", opts.ComponentNamespace)
// ComponentNamespace should either be the default or read from the service account namespace file
if opts.ComponentNamespace == "" {
t.Errorf("ComponentNamespace should not be empty")
}
// In test environments, it may be read from /var/run/secrets/kubernetes.io/serviceaccount/namespace
// Otherwise, it should be the default value
if _, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace"); err != nil {
// No service account namespace file, should be default
if opts.ComponentNamespace != "open-cluster-management-agent" {
t.Errorf("unexpected ComponentNamespace: %s", opts.ComponentNamespace)
}
}
}