From c9f3ff01903b1741837e9a9a8b96eeeff41cde0b Mon Sep 17 00:00:00 2001 From: AhmedGrati Date: Fri, 14 Jul 2023 16:18:29 +0100 Subject: [PATCH] test: add unit-test for read only fs support Signed-off-by: AhmedGrati --- pkg/transformer/kubernetes/k8sutils_test.go | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/transformer/kubernetes/k8sutils_test.go b/pkg/transformer/kubernetes/k8sutils_test.go index 410e666f6d..15cfd87fc5 100644 --- a/pkg/transformer/kubernetes/k8sutils_test.go +++ b/pkg/transformer/kubernetes/k8sutils_test.go @@ -629,3 +629,31 @@ func TestArgsInterpolation(t *testing.T) { } } } + +func TestReadOnlyRootFS(t *testing.T) { + // An example service + service := kobject.ServiceConfig{ + ContainerName: "name", + Image: "image", + ReadOnly: true, + } + + // An example object generated via k8s runtime.Objects() + komposeObject := kobject.KomposeObject{ + ServiceConfigs: map[string]kobject.ServiceConfig{"app": service}, + } + k := Kubernetes{} + objects, err := k.Transform(komposeObject, kobject.ConvertOptions{CreateD: true}) + if err != nil { + t.Error(errors.Wrap(err, "k.Transform failed")) + } + + for _, obj := range objects { + if deployment, ok := obj.(*appsv1.Deployment); ok { + readOnlyFS := deployment.Spec.Template.Spec.Containers[0].SecurityContext.ReadOnlyRootFilesystem + if *readOnlyFS != true { + t.Errorf("Expected ReadOnlyRootFileSystem %v upon conversion, actual %v", true, readOnlyFS) + } + } + } +}