Skip to content

Commit

Permalink
Add test to verify volume/volumemount order is deterministic
Browse files Browse the repository at this point in the history
This test is to verify that the order of volume and volumemounts.
Without the sort that was added in the previous commit, the order
is not deterministic and this test would thus fail some of the time
without sorting.
  • Loading branch information
popsu committed Sep 20, 2023
1 parent 40d9ba0 commit 425ed76
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions controllers/eventsource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,93 @@ func Test_BuildDeployment(t *testing.T) {
assert.True(t, hasTLSSecretVolume)
assert.True(t, hasTLSSecretVolumeMount)
})

t.Run("test secret volume and volumemount order deterministic", func(t *testing.T) {
args := &AdaptorArgs{
Image: testImage,
EventSource: testEventSource,
Labels: testLabels,
}

webhooksWithSecrets := map[string]v1alpha1.WebhookEventSource{
"webhook4": {
WebhookContext: v1alpha1.WebhookContext{
URL: "http://a.b",
Endpoint: "/webhook4",
Port: "1234",
AuthSecret: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: "webhook4"},
Key: "secret",
},
},
},
"webhook3": {
WebhookContext: v1alpha1.WebhookContext{
URL: "http://a.b",
Endpoint: "/webhook3",
Port: "1234",
AuthSecret: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: "webhook3"},
Key: "secret",
},
},
},
"webhook1": {
WebhookContext: v1alpha1.WebhookContext{
URL: "http://a.b",
Endpoint: "/webhook1",
Port: "1234",
AuthSecret: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: "webhook1"},
Key: "secret",
},
},
},
"webhook2": {
WebhookContext: v1alpha1.WebhookContext{
URL: "http://a.b",
Endpoint: "/webhook2",
Port: "1234",
AuthSecret: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: "webhook2"},
Key: "secret",
},
},
},
}
args.EventSource.Spec.Webhook = webhooksWithSecrets

wantVolumeNames := []string{"auth-volume", "cm-test-cm", "secret-test-secret", "secret-webhook1", "secret-webhook2", "secret-webhook3", "secret-webhook4", "tmp"}
wantVolumeMountNames := []string{"auth-volume", "cm-test-cm", "secret-test-secret", "secret-webhook1", "secret-webhook2", "secret-webhook3", "secret-webhook4", "tmp"}

deployment, err := buildDeployment(args, fakeEventBus)
assert.Nil(t, err)
assert.NotNil(t, deployment)
gotVolumes := deployment.Spec.Template.Spec.Volumes
gotVolumeMounts := deployment.Spec.Template.Spec.Containers[0].VolumeMounts

var gotVolumeNames []string
var gotVolumeMountNames []string

for _, v := range gotVolumes {
gotVolumeNames = append(gotVolumeNames, v.Name)
}
for _, v := range gotVolumeMounts {
gotVolumeMountNames = append(gotVolumeMountNames, v.Name)
}

assert.Equal(t, len(gotVolumes), len(wantVolumeNames))
assert.Equal(t, len(gotVolumeMounts), len(wantVolumeMountNames))

for i := range gotVolumeNames {
assert.Equal(t, gotVolumeNames[i], wantVolumeNames[i])
}
for i := range gotVolumeMountNames {
assert.Equal(t, gotVolumeMountNames[i], wantVolumeMountNames[i])
}

assert.Equal(t, deployment.Spec.Template.Spec.PriorityClassName, "test-class")
})
}

func TestResourceReconcile(t *testing.T) {
Expand Down

0 comments on commit 425ed76

Please sign in to comment.