Skip to content

Commit

Permalink
Add test for 'GetExternalConfig' (#2222)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cortey authored Sep 30, 2024
1 parent 6f73ee2 commit b426c8b
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion internal/registry/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,42 @@ import (
k8s_fake "k8s.io/client-go/kubernetes/fake"
)

func TestGetConfig(t *testing.T) {
func TestGetExternalConfig(t *testing.T) {
t.Run("Should return the ExternalRegistryConfig", func(t *testing.T) {
// given
testDockerRegistry := fixTestDockerRegistry()
testRegistrySecret := fixTestRegistrySecret()
client := k8s_fake.NewSimpleClientset(testRegistrySecret)
scheme := runtime.NewScheme()
scheme.AddKnownTypes(DockerRegistryGVR.GroupVersion(), testDockerRegistry)
dynamic := dynamic_fake.NewSimpleDynamicClient(scheme, testDockerRegistry)

expectedRegistryConfig := &ExternalRegistryConfig{
SecretName: testRegistrySecret.GetName(),
SecretData: &SecretData{
DockerConfigJSON: string(testRegistrySecret.Data[".dockerconfigjson"]),
Username: string(testRegistrySecret.Data["username"]),
Password: string(testRegistrySecret.Data["password"]),
PullRegAddr: string(testRegistrySecret.Data["pullRegAddr"]),
PushRegAddr: string(testRegistrySecret.Data["pushRegAddr"]),
},
}

kubeClient := &kube_fake.FakeKubeClient{
TestKubernetesInterface: client,
TestDynamicInterface: dynamic,
}

// when
config, err := GetExternalConfig(context.Background(), kubeClient)

// then
require.Nil(t, err)
require.Equal(t, expectedRegistryConfig, config)
})
}

func TestGetInternalConfig(t *testing.T) {
t.Run("Should return the InternalRegistryConfig", func(t *testing.T) {
// given
testRegistrySvc := fixTestRegistrySvc()
Expand Down Expand Up @@ -200,6 +235,10 @@ func fixTestDockerRegistry() *unstructured.Unstructured {
"internalAccess": map[string]interface{}{
"secretName": "test-secret",
},
"externalAccess": map[string]interface{}{
"secretName": "test-secret",
"enabled": "true",
},
"state": "Ready",
},
},
Expand Down

0 comments on commit b426c8b

Please sign in to comment.