Skip to content

Commit

Permalink
Merge pull request #179 from CasperGN/Fix-test-case
Browse files Browse the repository at this point in the history
Correct test-case for ContainerSecurityContext
  • Loading branch information
alex-arica authored Mar 20, 2024
2 parents fe410e4 + deef59d commit 4b231de
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/test/spec_containerSecurityContext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
var _ = Describe("Setting Kubegres spec 'containerSecurityContext'", func() {
var test = SpeccontainerSecurityContextTest{}
BeforeEach(func() {
Skip("Temporarily skipping test")

namespace := resourceConfigs2.DefaultNamespace
test.resourceRetriever = util2.CreateTestResourceRetriever(k8sClientTest, namespace)
test.resourceCreator = util2.CreateTestResourceCreator(k8sClientTest, test.resourceRetriever, namespace)
Expand Down Expand Up @@ -65,8 +63,9 @@ var _ = Describe("Setting Kubegres spec 'containerSecurityContext'", func() {
log.Print("START OF: Test 'GIVEN new Kubegres is created with spec 'containerSecurityContext' set to a value and spec 'replica' set to 3")

securityContext := test.givencontainerSecurityContext1()
podSecurityContext := &v12.PodSecurityContext{RunAsUser: pointer.Int64Ptr(1000)}

test.givenNewKubegresSpecIsSetTo(securityContext, 3)
test.givenNewKubegresSpecIsSetTo(securityContext, podSecurityContext, 3)

test.whenKubegresIsCreated()

Expand Down Expand Up @@ -119,7 +118,7 @@ func (r *SpeccontainerSecurityContextTest) givencontainerSecurityContext1() *v12
AllowPrivilegeEscalation: pointer.BoolPtr(false),
Capabilities: &v12.Capabilities{Drop: []v12.Capability{"ALL"}},
SeccompProfile: &v12.SeccompProfile{Type: v12.SeccompProfileTypeRuntimeDefault},
ReadOnlyRootFilesystem: pointer.BoolPtr(true),
ReadOnlyRootFilesystem: pointer.BoolPtr(false),
Privileged: pointer.BoolPtr(false),
}
}
Expand All @@ -140,9 +139,10 @@ func (r *SpeccontainerSecurityContextTest) givenNewKubegresSpecIsWithoutcontaine
r.kubegresResource.Spec.Replicas = &replicaCount
}

func (r *SpeccontainerSecurityContextTest) givenNewKubegresSpecIsSetTo(securityContext *v12.SecurityContext, specNbreReplicas int32) {
func (r *SpeccontainerSecurityContextTest) givenNewKubegresSpecIsSetTo(securityContext *v12.SecurityContext, podSecurityContext *v12.PodSecurityContext, specNbreReplicas int32) {
r.kubegresResource = resourceConfigs2.LoadKubegresYaml()
r.kubegresResource.Spec.ContainerSecurityContext = securityContext
r.kubegresResource.Spec.SecurityContext = podSecurityContext
r.kubegresResource.Spec.Replicas = &specNbreReplicas
}

Expand Down Expand Up @@ -181,7 +181,7 @@ func (r *SpeccontainerSecurityContextTest) thenStatefulSetStatesShouldBeWithoutc
emptyResources := &v12.SecurityContext{}
if !reflect.DeepEqual(currentContainerSecurityContext, emptyResources) {
log.Println("StatefulSet '" + resource.StatefulSet.Name + "' has not the expected containerSecurityContext which should be nil" +
"Current valye: '" + currentContainerSecurityContext.String() + "'. Waiting...")
"Current value: '" + currentContainerSecurityContext.String() + "'. Waiting...")
return false
}

Expand All @@ -190,7 +190,7 @@ func (r *SpeccontainerSecurityContextTest) thenStatefulSetStatesShouldBeWithoutc
currentInitContainerSecurityContext := resource.StatefulSet.Spec.Template.Spec.InitContainers[0].SecurityContext
if !reflect.DeepEqual(currentInitContainerSecurityContext, emptyResources) {
log.Println("StatefulSet '" + resource.StatefulSet.Name + "' has not the expected initContainerSecurityContext which should be nil" +
"Current valye: '" + currentInitContainerSecurityContext.String() + "'. Waiting...")
"Current value: '" + currentInitContainerSecurityContext.String() + "'. Waiting...")
return false
}
}
Expand Down Expand Up @@ -233,7 +233,7 @@ func (r *SpeccontainerSecurityContextTest) thenStatefulSetStatesShouldBe(expecte
currentInitContainerSecurityContext := resource.StatefulSet.Spec.Template.Spec.InitContainers[0].SecurityContext
if !reflect.DeepEqual(currentInitContainerSecurityContext, expectedContainerSecurityContext) {
log.Println("StatefulSet '" + resource.StatefulSet.Name + "' has not the expected initContainerSecurityContext which should be nil" +
"Current valye: '" + currentInitContainerSecurityContext.String() + "'. Waiting...")
"Current value: '" + currentInitContainerSecurityContext.String() + "'. Waiting...")
return false
}
}
Expand Down Expand Up @@ -263,7 +263,7 @@ func (r *SpeccontainerSecurityContextTest) thenDeployedKubegresSpecShouldWithout
return
}

Expect(r.kubegresResource.Spec.SecurityContext).Should(Equal(emptyResources))
Expect(r.kubegresResource.Spec.ContainerSecurityContext).Should(Equal(emptyResources))
}

func (r *SpeccontainerSecurityContextTest) thenDeployedKubegresSpecShouldBeSetTo(expectedcontainerSecurityContext *v12.SecurityContext) {
Expand Down

0 comments on commit 4b231de

Please sign in to comment.