(t *testing.T)
| 3031 | } |
| 3032 | |
| 3033 | func TestTransformNodeStatusExporter(t *testing.T) { |
| 3034 | testCases := []struct { |
| 3035 | description string |
| 3036 | ds Daemonset |
| 3037 | cpSpec *gpuv1.ClusterPolicySpec |
| 3038 | expectedDs Daemonset |
| 3039 | errorExpected bool |
| 3040 | }{ |
| 3041 | { |
| 3042 | description: "empty node status exporter spec", |
| 3043 | ds: NewDaemonset(). |
| 3044 | WithContainer(corev1.Container{Name: "dummy"}), |
| 3045 | cpSpec: &gpuv1.ClusterPolicySpec{ |
| 3046 | NodeStatusExporter: gpuv1.NodeStatusExporterSpec{}, |
| 3047 | }, |
| 3048 | expectedDs: NewDaemonset(), |
| 3049 | errorExpected: true, |
| 3050 | }, |
| 3051 | { |
| 3052 | description: "valid node status exporter spec", |
| 3053 | ds: NewDaemonset(). |
| 3054 | WithContainer(corev1.Container{Name: "dummy"}), |
| 3055 | cpSpec: &gpuv1.ClusterPolicySpec{ |
| 3056 | NodeStatusExporter: gpuv1.NodeStatusExporterSpec{ |
| 3057 | Repository: "nvcr.io/nvidia/cloud-native", |
| 3058 | Image: "node-status-exporter", |
| 3059 | Version: "v1.0.0", |
| 3060 | ImagePullPolicy: "IfNotPresent", |
| 3061 | }, |
| 3062 | }, |
| 3063 | expectedDs: NewDaemonset(). |
| 3064 | WithContainer(corev1.Container{ |
| 3065 | Name: "dummy", |
| 3066 | Image: "nvcr.io/nvidia/cloud-native/node-status-exporter:v1.0.0", |
| 3067 | ImagePullPolicy: corev1.PullIfNotPresent, |
| 3068 | SecurityContext: &corev1.SecurityContext{ |
| 3069 | RunAsUser: rootUID, |
| 3070 | }, |
| 3071 | }), |
| 3072 | }, |
| 3073 | } |
| 3074 | |
| 3075 | for _, tc := range testCases { |
| 3076 | t.Run(tc.description, func(t *testing.T) { |
| 3077 | err := TransformNodeStatusExporter(tc.ds.DaemonSet, tc.cpSpec, ClusterPolicyController{runtime: gpuv1.Containerd, logger: ctrl.Log.WithName("test")}) |
| 3078 | if tc.errorExpected { |
| 3079 | require.Error(t, err) |
| 3080 | return |
| 3081 | } |
| 3082 | require.NoError(t, err) |
| 3083 | require.EqualValues(t, tc.expectedDs, tc.ds) |
| 3084 | }) |
| 3085 | } |
| 3086 | } |
| 3087 | |
| 3088 | func TestTransformDriver(t *testing.T) { |
| 3089 | initMockK8sClients() |
nothing calls this directly
no test coverage detected