Skip to content

Commit

Permalink
Add utests for missing pod UID
Browse files Browse the repository at this point in the history
Signed-off-by: Arnon Gilboa <[email protected]>
  • Loading branch information
arnongilboa committed Mar 27, 2024
1 parent da6161f commit 4e41282
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ var testEnv = map[string]string{
kconfig.PodUIDEnvVarName: testPodUID,
}

var testEnvNoPodUID = map[string]string{
kconfig.ConfigMapNamespaceEnvVarName: testNamespace,
kconfig.ConfigMapNameEnvVarName: testConfigMapName,
kconfig.PodNameEnvVarName: testPodName,
}

func TestInitConfigMapShouldFailWhenNoConfigMap(t *testing.T) {
fakeClient := fake.NewSimpleClientset()
_, err := config.ReadWithDefaults(fakeClient, testNamespace, testEnv)
Expand All @@ -62,6 +68,27 @@ func TestInitConfigMapShouldFailWhenNoEnvVars(t *testing.T) {
assert.ErrorContains(t, err, "no environment variables")
}

func TestInitConfigMapShouldSucceedWithMissingPodID(t *testing.T) {
testPod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: testPodName,
Namespace: testNamespace,
},
}
fakeClient := fake.NewSimpleClientset(newConfigMap(), testPod)
_, err := config.ReadWithDefaults(fakeClient, testNamespace, testEnvNoPodUID)
assert.NoError(t, err)

_, err = kconfigmap.Get(fakeClient, testNamespace, testConfigMapName)
assert.NoError(t, err)
}

func TestInitConfigMapShouldFailWithMissingPodIDAndMissingPod(t *testing.T) {
fakeClient := fake.NewSimpleClientset(newConfigMap())
_, err := config.ReadWithDefaults(fakeClient, testNamespace, testEnvNoPodUID)
assert.ErrorContains(t, err, "not found")
}

func TestInitConfigMapShouldSucceed(t *testing.T) {
fakeClient := fake.NewSimpleClientset(newConfigMap())
_, err := config.ReadWithDefaults(fakeClient, testNamespace, testEnv)
Expand Down

0 comments on commit 4e41282

Please sign in to comment.