From 269f604094a9db722b4f622ef5c4146c95a3e9a7 Mon Sep 17 00:00:00 2001 From: Suraj Narwade Date: Thu, 14 Sep 2017 16:57:59 +0530 Subject: [PATCH] Fixed `--volumes` validation Now, `--volumes` argument will validate it's input, it will only allow `persistentVolumeClaim` or `emptyDir`, otherwise it will throw an error. --- pkg/app/app.go | 4 ++++ pkg/loader/compose/compose_test.go | 2 +- script/test/cmd/tests.sh | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/app/app.go b/pkg/app/app.go index c4d30edf..21a819f0 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -133,6 +133,10 @@ func ValidateFlags(bundle string, args []string, cmd *cobra.Command, opt *kobjec if opt.GenerateJSON && opt.GenerateYaml { log.Fatalf("YAML and JSON format cannot be provided at the same time") } + + if opt.Volumes != "persistentVolumeClaim" && opt.Volumes != "emptyDir" { + log.Fatal("Unknown Volume type: ", opt.Volumes, ", possible values are: persistentVolumeClaim and emptyDir") + } } // ValidateComposeFile validated the compose file provided for conversion diff --git a/pkg/loader/compose/compose_test.go b/pkg/loader/compose/compose_test.go index e7f1c666..e9e64844 100644 --- a/pkg/loader/compose/compose_test.go +++ b/pkg/loader/compose/compose_test.go @@ -56,7 +56,7 @@ func TestParseHealthCheck(t *testing.T) { } if !reflect.DeepEqual(output, expected) { - t.Errorf("Structs are not equal, expected: %s, output: %s", expected, output) + t.Errorf("Structs are not equal, expected: %v, output: %v", expected, output) } } diff --git a/script/test/cmd/tests.sh b/script/test/cmd/tests.sh index 0b4e70c2..53178055 100755 --- a/script/test/cmd/tests.sh +++ b/script/test/cmd/tests.sh @@ -374,6 +374,9 @@ cmd="kompose convert -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/dock sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/output-k8s-empty-vols-template.json > /tmp/output-k8s.json convert::expect_success_and_warning "kompose convert -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/docker-compose.yml --stdout -j --volumes emptyDir" "/tmp/output-k8s.json" "Volume mount on the host "\"."\" isn't supported - ignoring path on the host" +#Failing test for `--volumes` option +convert::expect_failure "kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/docker-compose.yaml --volumes foobar" + # Test related to support docker-compose.yaml beside docker-compose.yml # Store the original path CURRENT_DIR=$(pwd)