(t *testing.T)
| 370 | } |
| 371 | |
| 372 | func TestResolveRelativePaths(t *testing.T) { |
| 373 | pathResolutionConfig1 := clientcmdapi.Config{ |
| 374 | AuthInfos: map[string]*clientcmdapi.AuthInfo{ |
| 375 | "relative-user-1": {ClientCertificate: "relative/client/cert", ClientKey: "../relative/client/key"}, |
| 376 | "absolute-user-1": {ClientCertificate: "/absolute/client/cert", ClientKey: "/absolute/client/key"}, |
| 377 | "relative-cmd-1": {Exec: &clientcmdapi.ExecConfig{Command: "../relative/client/cmd"}}, |
| 378 | "absolute-cmd-1": {Exec: &clientcmdapi.ExecConfig{Command: "/absolute/client/cmd"}}, |
| 379 | "PATH-cmd-1": {Exec: &clientcmdapi.ExecConfig{Command: "cmd"}}, |
| 380 | }, |
| 381 | Clusters: map[string]*clientcmdapi.Cluster{ |
| 382 | "relative-server-1": {CertificateAuthority: "../relative/ca"}, |
| 383 | "absolute-server-1": {CertificateAuthority: "/absolute/ca"}, |
| 384 | }, |
| 385 | } |
| 386 | pathResolutionConfig2 := clientcmdapi.Config{ |
| 387 | AuthInfos: map[string]*clientcmdapi.AuthInfo{ |
| 388 | "relative-user-2": {ClientCertificate: "relative/client/cert2", ClientKey: "../relative/client/key2"}, |
| 389 | "absolute-user-2": {ClientCertificate: "/absolute/client/cert2", ClientKey: "/absolute/client/key2"}, |
| 390 | }, |
| 391 | Clusters: map[string]*clientcmdapi.Cluster{ |
| 392 | "relative-server-2": {CertificateAuthority: "../relative/ca2"}, |
| 393 | "absolute-server-2": {CertificateAuthority: "/absolute/ca2"}, |
| 394 | }, |
| 395 | } |
| 396 | |
| 397 | configDir1, _ := ioutil.TempDir("", "") |
| 398 | defer os.RemoveAll(configDir1) |
| 399 | configFile1 := path.Join(configDir1, ".kubeconfig") |
| 400 | configDir1, _ = filepath.Abs(configDir1) |
| 401 | |
| 402 | configDir2, _ := ioutil.TempDir("", "") |
| 403 | defer os.RemoveAll(configDir2) |
| 404 | configDir2, _ = ioutil.TempDir(configDir2, "") |
| 405 | configFile2 := path.Join(configDir2, ".kubeconfig") |
| 406 | configDir2, _ = filepath.Abs(configDir2) |
| 407 | |
| 408 | WriteToFile(pathResolutionConfig1, configFile1) |
| 409 | WriteToFile(pathResolutionConfig2, configFile2) |
| 410 | |
| 411 | loadingRules := ClientConfigLoadingRules{ |
| 412 | Precedence: []string{configFile1, configFile2}, |
| 413 | } |
| 414 | |
| 415 | mergedConfig, err := loadingRules.Load() |
| 416 | if err != nil { |
| 417 | t.Errorf("Unexpected error: %v", err) |
| 418 | } |
| 419 | |
| 420 | foundClusterCount := 0 |
| 421 | for key, cluster := range mergedConfig.Clusters { |
| 422 | if key == "relative-server-1" { |
| 423 | foundClusterCount++ |
| 424 | matchStringArg(path.Join(configDir1, pathResolutionConfig1.Clusters["relative-server-1"].CertificateAuthority), cluster.CertificateAuthority, t) |
| 425 | } |
| 426 | if key == "relative-server-2" { |
| 427 | foundClusterCount++ |
| 428 | matchStringArg(path.Join(configDir2, pathResolutionConfig2.Clusters["relative-server-2"].CertificateAuthority), cluster.CertificateAuthority, t) |
| 429 | } |
nothing calls this directly
no test coverage detected