Add tests for unsupported keys in k8s transformer

This commit is contained in:
Tomas Kral 2016-12-12 15:20:10 +01:00 committed by Ratnadeep Debnath
parent d5d0a3f03a
commit af9c6585ee

View File

@ -18,6 +18,8 @@ package kubernetes
import ( import (
"fmt" "fmt"
"reflect"
"strings"
"testing" "testing"
deployapi "github.com/openshift/origin/pkg/deploy/api" 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, "', '"))
}
}
}