From bb94d4e7763b594c1e16e0eca057c2b7e3081fca Mon Sep 17 00:00:00 2001 From: AhmedGrati Date: Thu, 13 Jul 2023 20:59:34 +0100 Subject: [PATCH] test: add functional tests Signed-off-by: AhmedGrati --- cmd/convert.go | 2 +- script/test/cmd/tests_new.sh | 10 +- .../fixtures/namespace/docker-compose.yaml | 6 + .../test/fixtures/namespace/output-k8s.yaml | 62 +++++++++++ script/test/fixtures/namespace/output-os.yaml | 104 ++++++++++++++++++ 5 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 script/test/fixtures/namespace/docker-compose.yaml create mode 100644 script/test/fixtures/namespace/output-k8s.yaml create mode 100644 script/test/fixtures/namespace/output-os.yaml diff --git a/cmd/convert.go b/cmd/convert.go index 3f2d95b46..c2972f551 100644 --- a/cmd/convert.go +++ b/cmd/convert.go @@ -188,7 +188,7 @@ func init() { convertCmd.Flags().IntVar(&ConvertReplicas, "replicas", 1, "Specify the number of replicas in the generated resource spec") convertCmd.Flags().StringVar(&ConvertVolumes, "volumes", "persistentVolumeClaim", `Volumes to be generated ("persistentVolumeClaim"|"emptyDir"|"hostPath" | "configMap")`) convertCmd.Flags().StringVar(&ConvertPVCRequestSize, "pvc-request-size", "", `Specify the size of pvc storage requests in the generated resource spec`) - convertCmd.Flags().StringVar(&ConvertNamespace, "namespace", "n", `Specify the namespace of the generated resources`) + convertCmd.Flags().StringVarP(&ConvertNamespace, "namespace", "n", "", `Specify the namespace of the generated resources`) convertCmd.Flags().BoolVar(&GenerateNetworkPolicies, "generate-network-policies", false, "Specify whether to generate network policies or not.") convertCmd.Flags().BoolVar(&WithKomposeAnnotation, "with-kompose-annotation", true, "Add kompose annotations to generated resource") diff --git a/script/test/cmd/tests_new.sh b/script/test/cmd/tests_new.sh index b44d3ef0d..2504a771f 100755 --- a/script/test/cmd/tests_new.sh +++ b/script/test/cmd/tests_new.sh @@ -271,11 +271,19 @@ convert::expect_success "$os_cmd" "$os_output" # Test support for network policies generation k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/network-policies/docker-compose.yaml convert --generate-network-policies --stdout --with-kompose-annotation=false" k8s_output="$KOMPOSE_ROOT/script/test/fixtures/network-policies/output-k8s.yaml" -convert::expect_success "$os_cmd" "$os_output" +convert::expect_success "$k8s_cmd" "$k8s_output" # Test support for custom build and push images k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/custom-build-push/docker-compose.yaml convert --build-command 'docker build -t ahmedgrati/kompose-test ./script/test/fixtures/custom-build-push' --push-command 'docker push ahmedgrati/kompose-test' --stdout --with-kompose-annotation=false" k8s_output="$KOMPOSE_ROOT/script/test/fixtures/custom-build-push/output-k8s.yaml" +convert::expect_success "$k8s_cmd" "$k8s_output" + +# Test support for namespace generation +k8s_cmd="kompose -f ./script/test/fixtures/namespace/docker-compose.yaml convert --stdout --with-kompose-annotation=false -n web" +k8s_output="$KOMPOSE_ROOT/script/test/fixtures/namespace/output-k8s.yaml" +os_cmd="kompose -f ./script/test/fixtures/namespace/docker-compose.yaml convert --stdout --with-kompose-annotation=false -n web --provider openshift" +os_output="$KOMPOSE_ROOT/script/test/fixtures/namespace/output-os.yaml" +convert::expect_success "$k8s_cmd" "$k8s_output" convert::expect_success "$os_cmd" "$os_output" # Test support for read only root fs diff --git a/script/test/fixtures/namespace/docker-compose.yaml b/script/test/fixtures/namespace/docker-compose.yaml new file mode 100644 index 000000000..a7ef6e52f --- /dev/null +++ b/script/test/fixtures/namespace/docker-compose.yaml @@ -0,0 +1,6 @@ +version: '3' +services: + web: + image: nginx + ports: + - 80:80 diff --git a/script/test/fixtures/namespace/output-k8s.yaml b/script/test/fixtures/namespace/output-k8s.yaml new file mode 100644 index 000000000..5d262bfcf --- /dev/null +++ b/script/test/fixtures/namespace/output-k8s.yaml @@ -0,0 +1,62 @@ +--- +apiVersion: v1 +kind: Service +metadata: + creationTimestamp: null + labels: + io.kompose.service: web + name: web + namespace: web +spec: + ports: + - name: "80" + port: 80 + targetPort: 80 + selector: + io.kompose.service: web +status: + loadBalancer: {} + +--- +apiVersion: v1 +kind: Namespace +metadata: + creationTimestamp: null + name: web + namespace: web +spec: {} +status: {} + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + creationTimestamp: null + labels: + io.kompose.service: web + name: web + namespace: web +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: web + strategy: {} + template: + metadata: + creationTimestamp: null + labels: + io.kompose.network/namespace-default: "true" + io.kompose.service: web + spec: + containers: + - image: nginx + name: web + ports: + - containerPort: 80 + hostPort: 80 + protocol: TCP + resources: {} + restartPolicy: Always +status: {} + diff --git a/script/test/fixtures/namespace/output-os.yaml b/script/test/fixtures/namespace/output-os.yaml new file mode 100644 index 000000000..65c150733 --- /dev/null +++ b/script/test/fixtures/namespace/output-os.yaml @@ -0,0 +1,104 @@ +--- +apiVersion: v1 +kind: Service +metadata: + creationTimestamp: null + labels: + io.kompose.service: web + name: web + namespace: web +spec: + ports: + - name: "80" + port: 80 + targetPort: 80 + selector: + io.kompose.service: web +status: + loadBalancer: {} + +--- +apiVersion: v1 +kind: Namespace +metadata: + creationTimestamp: null + name: web + namespace: web +spec: {} +status: {} + +--- +apiVersion: apps.openshift.io/v1 +kind: DeploymentConfig +metadata: + creationTimestamp: null + labels: + io.kompose.service: web + name: web + namespace: web +spec: + replicas: 1 + selector: + io.kompose.service: web + strategy: + resources: {} + template: + metadata: + creationTimestamp: null + labels: + io.kompose.network/namespace-default: "true" + io.kompose.service: web + spec: + containers: + - image: ' ' + name: web + ports: + - containerPort: 80 + hostPort: 80 + protocol: TCP + resources: {} + restartPolicy: Always + test: false + triggers: + - type: ConfigChange + - imageChangeParams: + automatic: true + containerNames: + - web + from: + kind: ImageStreamTag + name: web:latest + type: ImageChange +status: + availableReplicas: 0 + latestVersion: 0 + observedGeneration: 0 + replicas: 0 + unavailableReplicas: 0 + updatedReplicas: 0 + +--- +apiVersion: image.openshift.io/v1 +kind: ImageStream +metadata: + creationTimestamp: null + labels: + io.kompose.service: web + name: web + namespace: web +spec: + lookupPolicy: + local: false + tags: + - annotations: null + from: + kind: DockerImage + name: nginx + generation: null + importPolicy: {} + name: latest + referencePolicy: + type: "" +status: + dockerImageRepository: "" +