MCPcopy Create free account
hub / github.com/NVIDIA/gpu-operator / TestTransformValidationInitContainer

Function TestTransformValidationInitContainer

controllers/transforms_test.go:2283–2338  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2281}
2282
2283func TestTransformValidationInitContainer(t *testing.T) {
2284 testCases := []struct {
2285 description string
2286 ds Daemonset
2287 cpSpec *gpuv1.ClusterPolicySpec
2288 expectedDs Daemonset
2289 }{
2290 {
2291 description: "transform both driver and toolkit validation initContainers",
2292 ds: NewDaemonset().
2293 WithInitContainer(corev1.Container{Name: "driver-validation"}).
2294 WithInitContainer(corev1.Container{Name: "toolkit-validation"}).
2295 WithInitContainer(corev1.Container{Name: "dummy"}),
2296 cpSpec: &gpuv1.ClusterPolicySpec{
2297 Validator: gpuv1.ValidatorSpec{
2298 Repository: "nvcr.io/nvidia/cloud-native",
2299 Image: "gpu-operator-validator",
2300 Version: "v1.0.0",
2301 ImagePullPolicy: "IfNotPresent",
2302 ImagePullSecrets: []string{"pull-secret"},
2303 Driver: gpuv1.DriverValidatorSpec{
2304 Env: []gpuv1.EnvVar{{Name: "foo", Value: "bar"}},
2305 },
2306 Toolkit: gpuv1.ToolkitValidatorSpec{
2307 Env: []gpuv1.EnvVar{{Name: "foo", Value: "bar"}},
2308 },
2309 },
2310 },
2311 expectedDs: NewDaemonset().WithInitContainer(corev1.Container{
2312 Name: "driver-validation",
2313 Image: "nvcr.io/nvidia/cloud-native/gpu-operator-validator:v1.0.0",
2314 ImagePullPolicy: corev1.PullIfNotPresent,
2315 Env: []corev1.EnvVar{{Name: "foo", Value: "bar"}},
2316 SecurityContext: &corev1.SecurityContext{
2317 RunAsUser: rootUID,
2318 },
2319 }).WithInitContainer(corev1.Container{
2320 Name: "toolkit-validation",
2321 Image: "nvcr.io/nvidia/cloud-native/gpu-operator-validator:v1.0.0",
2322 ImagePullPolicy: corev1.PullIfNotPresent,
2323 Env: []corev1.EnvVar{{Name: "foo", Value: "bar"}},
2324 SecurityContext: &corev1.SecurityContext{
2325 RunAsUser: rootUID,
2326 },
2327 }).WithInitContainer(corev1.Container{Name: "dummy"}).WithPullSecret("pull-secret"),
2328 },
2329 }
2330
2331 for _, tc := range testCases {
2332 t.Run(tc.description, func(t *testing.T) {
2333 err := transformValidationInitContainer(tc.ds.DaemonSet, tc.cpSpec)
2334 require.NoError(t, err)
2335 require.EqualValues(t, tc.expectedDs, tc.ds)
2336 })
2337 }
2338}
2339
2340func newBoolPtr(b bool) *bool {

Callers

nothing calls this directly

Calls 5

NewDaemonsetFunction · 0.85
WithPullSecretMethod · 0.80
RunMethod · 0.80
WithInitContainerMethod · 0.45

Tested by

no test coverage detected