Merge pull request #111656 from Octopusjust/k8s-pr7

Add test for cmd/kubeadm/app/cmd/util/cmdutil.go
This commit is contained in:
Kubernetes Prow Robot 2022-08-23 17:16:40 -07:00 committed by GitHub
commit 94c70776ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,8 @@ package util
import (
"testing"
"k8s.io/client-go/tools/clientcmd"
)
func TestValidateExactArgNumber(t *testing.T) {
@ -70,3 +72,34 @@ func TestValidateExactArgNumber(t *testing.T) {
})
}
}
func TestGetKubeConfigPath(t *testing.T) {
var tests = []struct {
name string
file string
expected string
}{
{
name: "provide an empty value",
file: "",
expected: clientcmd.NewDefaultClientConfigLoadingRules().GetDefaultFilename(),
},
{
name: "provide a non-empty value",
file: "kubelet.kubeconfig",
expected: "kubelet.kubeconfig",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actualResult := GetKubeConfigPath(tt.file)
if actualResult != tt.expected {
t.Errorf(
"failed GetKubeConfigPath:\n\texpected: %s\n\t actual: %s",
tt.expected,
actualResult,
)
}
})
}
}