Add basic unit test for image mirror country
parent
e7af223d72
commit
dc6b9bae2b
|
@ -70,6 +70,50 @@ func TestGetKuberneterVersion(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestMirrorCountry(t *testing.T) {
|
||||
// Set default disk size value in lieu of flag init
|
||||
viper.SetDefault(humanReadableDiskSize, defaultDiskSize)
|
||||
|
||||
k8sVersion := constants.DefaultKubernetesVersion
|
||||
var tests = []struct {
|
||||
description string
|
||||
k8sVersion string
|
||||
imageRepository string
|
||||
mirrorCountry string
|
||||
cfg *cfg.ClusterConfig
|
||||
}{
|
||||
{
|
||||
description: "image-repository none, image-mirror-country none",
|
||||
imageRepository: "",
|
||||
mirrorCountry: "",
|
||||
},
|
||||
{
|
||||
description: "image-repository auto, image-mirror-country none",
|
||||
imageRepository: "auto",
|
||||
mirrorCountry: "",
|
||||
},
|
||||
{
|
||||
description: "image-repository auto, image-mirror-country china",
|
||||
imageRepository: "auto",
|
||||
mirrorCountry: "cn",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.description, func(t *testing.T) {
|
||||
cmd := &cobra.Command{}
|
||||
viper.SetDefault(imageRepository, test.imageRepository)
|
||||
viper.SetDefault(imageMirrorCountry, test.mirrorCountry)
|
||||
config, _, err := generateCfgFromFlags(cmd, k8sVersion, "none")
|
||||
if err != nil {
|
||||
t.Fatalf("Got unexpected error %v during config generation", err)
|
||||
}
|
||||
// the result can still be "", but anyway
|
||||
_ = config.KubernetesConfig.ImageRepository
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateCfgFromFlagsHTTPProxyHandling(t *testing.T) {
|
||||
// Set default disk size value in lieu of flag init
|
||||
viper.SetDefault(humanReadableDiskSize, defaultDiskSize)
|
||||
|
|
Loading…
Reference in New Issue