|
| 1 | +//go:build all || tpl |
1 | 2 | // +build all tpl |
2 | 3 |
|
3 | 4 | // NOTE: We use build flags to differentiate between template tests and integration tests so that you can conveniently |
@@ -194,6 +195,44 @@ func TestK8SServiceVolumeConfigMapAddsVolumeAndVolumeMountWithoutSubPathToPod(t |
194 | 195 | assert.Empty(t, volumeMount.SubPath) |
195 | 196 | } |
196 | 197 |
|
| 198 | +// Test that setting the `secrets` input value with volume include the volume mount for the secret |
| 199 | +// We test by injecting to secrets: |
| 200 | +// secrets: |
| 201 | +// dbsettings: |
| 202 | +// as: volume |
| 203 | +// mountPath: /etc/db |
| 204 | +func TestK8SServiceVolumeSecretAddsVolumeAndVolumeMountWithoutSubPathToPod(t *testing.T) { |
| 205 | + t.Parallel() |
| 206 | + |
| 207 | + deployment := renderK8SServiceDeploymentWithSetValues( |
| 208 | + t, |
| 209 | + map[string]string{ |
| 210 | + "secrets.dbsettings.as": "volume", |
| 211 | + "secrets.dbsettings.mountPath": "/etc/db", |
| 212 | + }, |
| 213 | + ) |
| 214 | + |
| 215 | + // Verify that there is only one container and only one volume |
| 216 | + renderedPodContainers := deployment.Spec.Template.Spec.Containers |
| 217 | + require.Equal(t, len(renderedPodContainers), 1) |
| 218 | + appContainer := renderedPodContainers[0] |
| 219 | + renderedPodVolumes := deployment.Spec.Template.Spec.Volumes |
| 220 | + require.Equal(t, len(renderedPodVolumes), 1) |
| 221 | + podVolume := renderedPodVolumes[0] |
| 222 | + |
| 223 | + // Check that the pod volume is a secret volume |
| 224 | + assert.Equal(t, podVolume.Name, "dbsettings-volume") |
| 225 | + require.NotNil(t, podVolume.Secret) |
| 226 | + assert.Equal(t, podVolume.Secret.SecretName, "dbsettings") |
| 227 | + |
| 228 | + // Check that the pod volume will be mounted |
| 229 | + require.Equal(t, len(appContainer.VolumeMounts), 1) |
| 230 | + volumeMount := appContainer.VolumeMounts[0] |
| 231 | + assert.Equal(t, volumeMount.Name, "dbsettings-volume") |
| 232 | + assert.Equal(t, volumeMount.MountPath, "/etc/db") |
| 233 | + assert.Empty(t, volumeMount.SubPath) |
| 234 | +} |
| 235 | + |
197 | 236 | // Test that setting the `configMaps` input value with volume include the volume mount and subpath for the config map |
198 | 237 | // We test by injecting to configMaps: |
199 | 238 | // configMaps: |
@@ -234,6 +273,46 @@ func TestK8SServiceVolumeConfigMapAddsVolumeAndVolumeMountWithSubPathToPod(t *te |
234 | 273 | assert.Equal(t, volumeMount.SubPath, "host.txt") |
235 | 274 | } |
236 | 275 |
|
| 276 | +// Test that setting the `secrets` input value with volume include the volume mount and subpath for the secret |
| 277 | +// We test by injecting to secrets: |
| 278 | +// secrets: |
| 279 | +// dbsettings: |
| 280 | +// as: volume |
| 281 | +// mountPath: /etc/db/host.txt |
| 282 | +// subPath: host.xt |
| 283 | +func TestK8SServiceVolumeSecretAddsVolumeAndVolumeMountWithSubPathToPod(t *testing.T) { |
| 284 | + t.Parallel() |
| 285 | + |
| 286 | + deployment := renderK8SServiceDeploymentWithSetValues( |
| 287 | + t, |
| 288 | + map[string]string{ |
| 289 | + "secrets.dbsettings.as": "volume", |
| 290 | + "secrets.dbsettings.mountPath": "/etc/db/host.txt", |
| 291 | + "secrets.dbsettings.subPath": "host.txt", |
| 292 | + }, |
| 293 | + ) |
| 294 | + |
| 295 | + // Verify that there is only one container and only one volume |
| 296 | + renderedPodContainers := deployment.Spec.Template.Spec.Containers |
| 297 | + require.Equal(t, len(renderedPodContainers), 1) |
| 298 | + appContainer := renderedPodContainers[0] |
| 299 | + renderedPodVolumes := deployment.Spec.Template.Spec.Volumes |
| 300 | + require.Equal(t, len(renderedPodVolumes), 1) |
| 301 | + podVolume := renderedPodVolumes[0] |
| 302 | + |
| 303 | + // Check that the pod volume is a secret volume |
| 304 | + assert.Equal(t, podVolume.Name, "dbsettings-volume") |
| 305 | + require.NotNil(t, podVolume.Secret) |
| 306 | + assert.Equal(t, podVolume.Secret.SecretName, "dbsettings") |
| 307 | + |
| 308 | + // Check that the pod volume will be mounted |
| 309 | + require.Equal(t, len(appContainer.VolumeMounts), 1) |
| 310 | + volumeMount := appContainer.VolumeMounts[0] |
| 311 | + assert.Equal(t, volumeMount.Name, "dbsettings-volume") |
| 312 | + assert.Equal(t, volumeMount.MountPath, "/etc/db/host.txt") |
| 313 | + assert.Equal(t, volumeMount.SubPath, "host.txt") |
| 314 | +} |
| 315 | + |
237 | 316 | // Test that setting the `configMaps` input value with volume and individual file mount paths will set the appropriate |
238 | 317 | // settings |
239 | 318 | // We test by injecting to configMaps: |
|
0 commit comments