mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-02-14 18:09:57 +00:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user