Skip to content

Commit

Permalink
Add more unit tests for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderboltsid committed Mar 15, 2023
1 parent ef09260 commit 59966a2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/config/registry_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
24 changes: 24 additions & 0 deletions pkg/providers/nutanix/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 59966a2

Please sign in to comment.