Add test for cmd/kubeadm/app/cmd/util/cmdutil.go

This commit is contained in:
ZhangYu 2022-08-03 15:01:55 +08:00
parent aea9f9887d
commit 20affda7f7

View File

@ -17,6 +17,7 @@ limitations under the License.
package util package util
import ( import (
"k8s.io/client-go/tools/clientcmd"
"testing" "testing"
) )
@ -70,3 +71,29 @@ 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) {
if GetKubeConfigPath(tt.file) != tt.expected {
t.Error("unexpected result")
}
})
}
}