Skip to content

Commit

Permalink
Attempt to add to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelMue committed Dec 14, 2020
1 parent e27c210 commit 44abb80
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion pkg/reconciler/v1alpha1/eventlistener/eventlistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ func makeDeployment(ops ...func(d *appsv1.Deployment)) *appsv1.Deployment {
},
},
}},
SecurityContext: &corev1.PodSecurityContext{
RunAsNonRoot: ptr.Bool(true),
RunAsUser: ptr.Int64(65532),
},
},
},
},
Expand Down Expand Up @@ -323,6 +327,10 @@ var withTLSConfig = func(d *appsv1.Deployment) {
},
},
}},
SecurityContext: &corev1.SecurityContext{
RunAsNonRoot: ptr.Bool(true),
RunAsUser: ptr.Int64(65532),
},
}}
d.Spec.Template.Spec.Volumes = []corev1.Volume{{
Name: "config-logging",
Expand Down Expand Up @@ -598,6 +606,10 @@ func TestReconcile(t *testing.T) {
d.Spec.Template.Spec.Containers[0].VolumeMounts = nil
})

deploymentMissingSecurityContext := makeDeployment(func(d *appsv1.Deployment) {
d.Spec.Template.Spec.Containers[0].SecurityContext = nil
})

deploymentForKubernetesResource := makeDeployment(func(d *appsv1.Deployment) {
d.Spec.Template.Spec.ServiceAccountName = "k8sresource"
d.Spec.Template.Spec.NodeSelector = map[string]string{"key": "value"}
Expand Down Expand Up @@ -971,7 +983,24 @@ func TestReconcile(t *testing.T) {
Deployments: []*appsv1.Deployment{deploymentWithTLSConnection},
Services: []*corev1.Service{elServiceWithTLSConnection},
},
}}
}, {
name: "eventlistener with security context",
key: reconcileKey,
startResources: test.Resources{
Namespaces: []*corev1.Namespace{namespaceResource},
EventListeners: []*v1alpha1.EventListener{elWithTLSConnection},
Deployments: []*appsv1.Deployment{deploymentMissingSecurityContext},
ConfigMaps: []*corev1.ConfigMap{loggingConfigMap},
},
endResources: test.Resources{
Namespaces: []*corev1.Namespace{namespaceResource},
EventListeners: []*v1alpha1.EventListener{makeEL(withStatus)},
Deployments: []*appsv1.Deployment{elDeployment},
Services: []*corev1.Service{elService},
ConfigMaps: []*corev1.ConfigMap{loggingConfigMap},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Setup with startResources
Expand Down

0 comments on commit 44abb80

Please sign in to comment.