Skip to content

Commit

Permalink
Add test for deterministic volume/volumemount order for sensor deploy…
Browse files Browse the repository at this point in the history
…ment

Signed-off-by: Tommi Hovi <[email protected]>
  • Loading branch information
popsu committed Sep 25, 2023
1 parent f73f0bf commit 91ea494
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions controllers/sensor/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,45 @@ func Test_BuildDeployment(t *testing.T) {
assert.True(t, hasTLSSecretVolume)
assert.True(t, hasTLSSecretVolumeMount)
})

t.Run("test secret volume and volumemount order determinisitc", func(t *testing.T) {

args := &AdaptorArgs{
Image: testImage,
Sensor: sensorObj,
Labels: testLabels,
}

wantVolumeNames := []string{"test-data", "auth-volume", "tmp"}
wantVolumeMountNames := []string{"test-data", "auth-volume", "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])
}
})

}

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

0 comments on commit 91ea494

Please sign in to comment.