Skip to content

Commit

Permalink
Correct the functional test for TLS mounts
Browse files Browse the repository at this point in the history
Signed-off-by: Veronika Fisarova <[email protected]>
  • Loading branch information
Deydra71 committed Oct 19, 2023
1 parent 64647f8 commit e2765db
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
32 changes: 32 additions & 0 deletions tests/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,35 @@ func PlacementConditionGetter(name types.NamespacedName) condition.Conditions {
instance := GetPlacementAPI(name)
return instance.Status.Conditions
}

func CreateMockTLSSecret(namespace string, name string) *corev1.Secret {
return th.CreateSecret(
types.NamespacedName{Namespace: namespace, Name: name},
map[string][]byte{
"tls.crt": []byte("mocked-cert-data"),
"tls.key": []byte("mocked-key-data"),
},
)
}

func CreatePlacementAPIWithTLS(name types.NamespacedName, spec map[string]interface{}, tlsSecretName string) client.Object {
spec["tlsSecretName"] = tlsSecretName

raw := map[string]interface{}{
"apiVersion": "placement.openstack.org/v1beta1",
"kind": "PlacementAPI",
"metadata": map[string]interface{}{
"name": name.Name,
"namespace": name.Namespace,
},
"spec": spec,
}
return th.CreateUnstructured(raw)
}

func CreatePlacementAPISecretWithTLS(namespace string, name string) *corev1.Secret {
secret := CreatePlacementAPISecret(namespace, name)
secret.Data["tls.crt"] = []byte("mocked-cert-data")
secret.Data["tls.key"] = []byte("mocked-key-data")
return secret
}
9 changes: 6 additions & 3 deletions tests/functional/placementapi_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,10 @@ var _ = Describe("PlacementAPI controller", func() {
var placementAPINames Names

BeforeEach(func() {
mockSecret := CreateMockTLSSecret(names.Namespace, "mocked-tls-secret")
specWithTLS := GetDefaultPlacementAPISpec()
instance := CreatePlacementAPI(names.PlacementAPIName, specWithTLS)
specWithTLS["tlsSecretName"] = mockSecret.Name
instance := CreatePlacementAPIWithTLS(names.PlacementAPIName, specWithTLS, mockSecret.Name)

placementAPINames = CreateNames(types.NamespacedName{
Namespace: instance.GetNamespace(),
Expand All @@ -714,8 +716,9 @@ var _ = Describe("PlacementAPI controller", func() {

container := deployment.Spec.Template.Spec.Containers[0]

Expect(container.VolumeMounts).To(ContainElement(HaveField("Name", Equal("tls-crt"))))
Expect(container.VolumeMounts).To(ContainElement(HaveField("Name", Equal("tls-key"))))
Expect(container.VolumeMounts).To(ContainElement(HaveField("MountPath", Equal("/etc/pki/tls/certs/tls.crt"))))
Expect(container.VolumeMounts).To(ContainElement(HaveField("MountPath", Equal("/etc/pki/tls/certs/tls.key"))))

Expect(container.VolumeMounts).To(ContainElement(HaveField("Name", Equal("ca-certs"))))
})
})
Expand Down

0 comments on commit e2765db

Please sign in to comment.