diff --git a/pkg/config/registry_test.go b/pkg/config/registry_test.go new file mode 100644 index 0000000000000..13f5615d1bacc --- /dev/null +++ b/pkg/config/registry_test.go @@ -0,0 +1,24 @@ +package config + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/aws/eks-anywhere/pkg/constants" +) + +func TestReadConfig(t *testing.T) { + _, _, err := ReadCredentials() + assert.Error(t, err) + + expectedUser := "testuser" + expectedPassword := "testpass" + t.Setenv(constants.RegistryUsername, expectedUser) + t.Setenv(constants.RegistryPassword, expectedPassword) + + username, password, err := ReadCredentials() + assert.NoError(t, err) + assert.Equal(t, expectedUser, username) + assert.Equal(t, expectedPassword, password) +} diff --git a/pkg/providers/nutanix/template_test.go b/pkg/providers/nutanix/template_test.go index 8310b77c65772..4837bb45f547a 100644 --- a/pkg/providers/nutanix/template_test.go +++ b/pkg/providers/nutanix/template_test.go @@ -176,6 +176,30 @@ func TestNewNutanixTemplateBuilderRegistryMirrorConfig(t *testing.T) { assert.Equal(t, expectedWorkersSpec, workerSpec) } +func TestNewNutanixTemplateBuilderRegistryMirrorConfigNoRegistryCredsSet(t *testing.T) { + dcConf, machineConf, workerConfs := minimalNutanixConfigSpec(t) + + t.Setenv(constants.EksaNutanixUsernameKey, "admin") + t.Setenv(constants.EksaNutanixPasswordKey, "password") + creds := GetCredsFromEnv() + builder := NewNutanixTemplateBuilder(&dcConf.Spec, &machineConf.Spec, &machineConf.Spec, workerConfs, creds, time.Now) + assert.NotNil(t, builder) + + buildSpec := test.NewFullClusterSpec(t, "testdata/eksa-cluster-registry-mirror.yaml") + + _, err := builder.GenerateCAPISpecControlPlane(buildSpec) + assert.Error(t, err) + + workloadTemplateNames := map[string]string{ + "eksa-unit-test": "eksa-unit-test", + } + kubeadmconfigTemplateNames := map[string]string{ + "eksa-unit-test": "eksa-unit-test", + } + _, err = builder.GenerateCAPISpecWorkers(buildSpec, workloadTemplateNames, kubeadmconfigTemplateNames) + assert.Error(t, err) +} + func minimalNutanixConfigSpec(t *testing.T) (*anywherev1.NutanixDatacenterConfig, *anywherev1.NutanixMachineConfig, map[string]anywherev1.NutanixMachineConfigSpec) { dcConf := &anywherev1.NutanixDatacenterConfig{} err := yaml.Unmarshal([]byte(nutanixDatacenterConfigSpec), dcConf)