From a881f5cca0cb504e43eac9b077d3dd4214ee7d1e Mon Sep 17 00:00:00 2001 From: Tuna Date: Mon, 28 Nov 2016 23:02:48 +0100 Subject: [PATCH] add test for key-only env --- script/test/cmd/tests.sh | 7 +- script/test/fixtures/keyonly-envs/env.yml | 25 ++ script/test/fixtures/keyonly-envs/envs | 1 + .../fixtures/keyonly-envs/output-k8s.json | 235 ++++++++++++++++++ 4 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 script/test/fixtures/keyonly-envs/env.yml create mode 100644 script/test/fixtures/keyonly-envs/envs create mode 100644 script/test/fixtures/keyonly-envs/output-k8s.json diff --git a/script/test/cmd/tests.sh b/script/test/cmd/tests.sh index 9ff0230d..06190858 100755 --- a/script/test/cmd/tests.sh +++ b/script/test/cmd/tests.sh @@ -103,7 +103,6 @@ convert::expect_success "kompose --bundle $KOMPOSE_ROOT/script/test/fixtures/bun # Test related to kompose --bundle convert to ensure that DSB bundles are converted properly convert::expect_success_and_warning "kompose --bundle $KOMPOSE_ROOT/script/test/fixtures/bundles/dsb/docker-voting-bundle.dsb convert --stdout" "$KOMPOSE_ROOT/script/test/fixtures/bundles/dsb/output-k8s.json" "Service cannot be created because of missing port." - ###### # Test related to restart options in docker-compose # kubernetes test @@ -113,4 +112,10 @@ convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-o convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-no.yml --provider openshift convert --stdout" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-os-restart-no.json" convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-onfail.yml --provider openshift convert --stdout" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-os-restart-onfail.json" +###### +# Test key-only envrionment variable +export $(cat $KOMPOSE_ROOT/script/test/fixtures/keyonly-envs/envs) +convert::expect_success "kompose --file $KOMPOSE_ROOT/script/test/fixtures/keyonly-envs/env.yml convert --stdout" "$KOMPOSE_ROOT/script/test/fixtures/keyonly-envs/output-k8s.json" +unset $(cat $KOMPOSE_ROOT/script/test/fixtures/keyonly-envs/envs | cut -d'=' -f1) + exit $EXIT_STATUS diff --git a/script/test/fixtures/keyonly-envs/env.yml b/script/test/fixtures/keyonly-envs/env.yml new file mode 100644 index 00000000..d13923f7 --- /dev/null +++ b/script/test/fixtures/keyonly-envs/env.yml @@ -0,0 +1,25 @@ +version: "2" + +services: + redis-master: + image: gcr.io/google_containers/redis:e2e + ports: + - "6379" + redis-slave: + image: gcr.io/google_samples/gb-redisslave:v1 + ports: + - "6379" + environment: + - GET_HOSTS_FROM=dns + - RACK_ENV=development + - SHOW=true + - SESSION_SECRET + frontend: + image: gcr.io/google-samples/gb-frontend:v4 + ports: + - "80:80" + environment: + GET_HOSTS_FROM: dns + RACK_ENV: development + SHOW: 'true' + SESSION_SECRET: diff --git a/script/test/fixtures/keyonly-envs/envs b/script/test/fixtures/keyonly-envs/envs new file mode 100644 index 00000000..870a7250 --- /dev/null +++ b/script/test/fixtures/keyonly-envs/envs @@ -0,0 +1 @@ +SESSION_SECRET=session diff --git a/script/test/fixtures/keyonly-envs/output-k8s.json b/script/test/fixtures/keyonly-envs/output-k8s.json new file mode 100644 index 00000000..c9bcf7ed --- /dev/null +++ b/script/test/fixtures/keyonly-envs/output-k8s.json @@ -0,0 +1,235 @@ +{ + "kind": "List", + "apiVersion": "v1", + "metadata": {}, + "items": [ + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "frontend", + "creationTimestamp": null, + "labels": { + "service": "frontend" + } + }, + "spec": { + "ports": [ + { + "name": "80", + "protocol": "TCP", + "port": 80, + "targetPort": 80 + } + ], + "selector": { + "service": "frontend" + } + }, + "status": { + "loadBalancer": {} + } + }, + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "redis-master", + "creationTimestamp": null, + "labels": { + "service": "redis-master" + } + }, + "spec": { + "ports": [ + { + "name": "6379", + "protocol": "TCP", + "port": 6379, + "targetPort": 6379 + } + ], + "selector": { + "service": "redis-master" + } + }, + "status": { + "loadBalancer": {} + } + }, + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "redis-slave", + "creationTimestamp": null, + "labels": { + "service": "redis-slave" + } + }, + "spec": { + "ports": [ + { + "name": "6379", + "protocol": "TCP", + "port": 6379, + "targetPort": 6379 + } + ], + "selector": { + "service": "redis-slave" + } + }, + "status": { + "loadBalancer": {} + } + }, + { + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "frontend", + "creationTimestamp": null + }, + "spec": { + "replicas": 1, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "frontend" + } + }, + "spec": { + "containers": [ + { + "name": "frontend", + "image": "gcr.io/google-samples/gb-frontend:v4", + "ports": [ + { + "containerPort": 80, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "GET_HOSTS_FROM", + "value": "dns" + }, + { + "name": "RACK_ENV", + "value": "development" + }, + { + "name": "SESSION_SECRET", + "value": "session" + }, + { + "name": "SHOW", + "value": "true" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} + }, + { + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "redis-master", + "creationTimestamp": null + }, + "spec": { + "replicas": 1, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "redis-master" + } + }, + "spec": { + "containers": [ + { + "name": "redis-master", + "image": "gcr.io/google_containers/redis:e2e", + "ports": [ + { + "containerPort": 6379, + "protocol": "TCP" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} + }, + { + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "redis-slave", + "creationTimestamp": null + }, + "spec": { + "replicas": 1, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "redis-slave" + } + }, + "spec": { + "containers": [ + { + "name": "redis-slave", + "image": "gcr.io/google_samples/gb-redisslave:v1", + "ports": [ + { + "containerPort": 6379, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "GET_HOSTS_FROM", + "value": "dns" + }, + { + "name": "RACK_ENV", + "value": "development" + }, + { + "name": "SHOW", + "value": "true" + }, + { + "name": "SESSION_SECRET", + "value": "session" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} + } + ] +}