Skip to content

Commit

Permalink
test: add unit-test for read only fs support
Browse files Browse the repository at this point in the history
Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com>
  • Loading branch information
TessaIO committed Jul 14, 2023
1 parent 4a08d41 commit c9f3ff0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/transformer/kubernetes/k8sutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}

0 comments on commit c9f3ff0

Please sign in to comment.