k8s.io/client-go: add ClientConfig option to override raw config

Kubernetes-commit: db80aa56ed8bcf4115e30fc62d27c8a8d8ec7f92
This commit is contained in:
Ivo Gosemann
2023-07-18 13:40:12 +02:00
committed by Kubernetes Publisher
parent 657d7be98b
commit 17b5405ddb
2 changed files with 116 additions and 0 deletions

View File

@@ -1013,3 +1013,72 @@ func TestCleanANSIEscapeCodes(t *testing.T) {
})
}
}
func TestMergeRawConfigDoOverride(t *testing.T) {
cfg := createValidTestConfig()
overrides := &ConfigOverrides{
ClusterInfo: clientcmdapi.Cluster{
Server: "http://localhost:8081",
},
Context: clientcmdapi.Context{
Namespace: "foobar",
Cluster: "clean",
AuthInfo: "clean",
},
AuthInfo: clientcmdapi.AuthInfo{
Token: "modified-token",
},
CurrentContext: "clean",
}
cut, err := NewClientConfigWithMergedRawConfig(*cfg, overrides)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
act, err := cut.RawConfig()
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if act.Clusters["clean"].Server != "http://localhost:8081" {
t.Errorf("Expected server %v, got %v", "http://localhost:8081", act.Clusters["clean"].Server)
}
if act.Contexts["clean"].Namespace != "foobar" {
t.Errorf("Expected namespace %v, got %v", "foobar", act.Contexts["clean"].Namespace)
}
}
func TestMergeRawConfigDoNotOverride(t *testing.T) {
cfg := createValidTestConfig()
overrides := &ConfigOverrides{
ClusterInfo: clientcmdapi.Cluster{
Server: "http://localhost:8081",
},
Context: clientcmdapi.Context{
Namespace: "foobar",
Cluster: "clean",
AuthInfo: "clean",
},
AuthInfo: clientcmdapi.AuthInfo{
Token: "modified-token",
},
CurrentContext: "clean",
}
cut := NewDefaultClientConfig(*cfg, overrides)
act, err := cut.RawConfig()
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if act.Clusters["clean"].Server != cfg.Clusters["clean"].Server {
t.Errorf("Expected server %v, got %v", cfg.Clusters["clean"].Server, act.Clusters["clean"].Server)
}
if act.Contexts["clean"].Namespace != cfg.Contexts["clean"].Namespace {
t.Errorf("Expected namespace %v, got %v", cfg.Contexts["clean"].Namespace, act.Contexts["clean"].Namespace)
}
}