Add basic unit test for image mirror country

pull/7054/head
Anders F Björklund 2020-03-15 12:52:35 +01:00
parent e7af223d72
commit dc6b9bae2b
1 changed files with 44 additions and 0 deletions

View File

@ -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)