From af9c6585eea1320f11e5caab457e4a76b55c7a1e Mon Sep 17 00:00:00 2001 From: Tomas Kral Date: Mon, 12 Dec 2016 15:20:10 +0100 Subject: [PATCH] Add tests for unsupported keys in k8s transformer --- pkg/transformer/kubernetes/kubernetes_test.go | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pkg/transformer/kubernetes/kubernetes_test.go b/pkg/transformer/kubernetes/kubernetes_test.go index 0c80e6e5..1319464e 100644 --- a/pkg/transformer/kubernetes/kubernetes_test.go +++ b/pkg/transformer/kubernetes/kubernetes_test.go @@ -18,6 +18,8 @@ package kubernetes import ( "fmt" + "reflect" + "strings" "testing" deployapi "github.com/openshift/origin/pkg/deploy/api" @@ -353,3 +355,36 @@ func TestConvertRestartOptions(t *testing.T) { } } } + +// TestUnsupportedKeys test checkUnsupportedKey function +func TestUnsupportedKeys(t *testing.T) { + + kobjectWithBuild := newKomposeObject() + kobjectWithBuild.LoadedFrom = "compose" + serviceConfig := kobjectWithBuild.ServiceConfigs["app"] + serviceConfig.Build = "./asdf" + serviceConfig.Network = []string{} + kobjectWithBuild.ServiceConfigs = map[string]kobject.ServiceConfig{"app": serviceConfig} + + // define all test cases for checkUnsupportedKey function + testCases := map[string]struct { + bundleFile kobject.KomposeObject + expectedUnsupportedKeys []string + }{ + "Full Bundle": { + kobjectWithBuild, + []string{"build"}, + }, + } + + k := Kubernetes{} + + for name, test := range testCases { + t.Log("Test case:", name) + keys := k.CheckUnsupportedKey(&test.bundleFile, unsupportedKey) + if !reflect.DeepEqual(keys, test.expectedUnsupportedKeys) { + t.Errorf("ERROR: Expecting unsupported keys: ['%s']. Got: ['%s']", strings.Join(test.expectedUnsupportedKeys, "', '"), strings.Join(keys, "', '")) + } + } + +}