2018-02-22 08:55:42 -05:00
|
|
|
package kubernetes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-03-05 18:53:52 -05:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2018-02-22 08:55:42 -05:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetStackAPIVersion(t *testing.T) {
|
|
|
|
var tests = []struct {
|
|
|
|
description string
|
|
|
|
groups *metav1.APIGroupList
|
|
|
|
err bool
|
|
|
|
expectedStack StackVersion
|
|
|
|
}{
|
|
|
|
{"no stack api", makeGroups(), true, ""},
|
|
|
|
{"v1beta1", makeGroups(groupVersion{"compose.docker.com", []string{"v1beta1"}}), false, StackAPIV1Beta1},
|
2018-01-31 09:37:14 -05:00
|
|
|
{"v1beta2", makeGroups(groupVersion{"compose.docker.com", []string{"v1beta2"}}), false, StackAPIV1Beta2},
|
|
|
|
{"most recent has precedence", makeGroups(groupVersion{"compose.docker.com", []string{"v1beta1", "v1beta2"}}), false, StackAPIV1Beta2},
|
2018-02-22 08:55:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
version, err := getAPIVersion(test.groups)
|
|
|
|
if test.err {
|
2017-12-21 16:27:57 -05:00
|
|
|
assert.ErrorContains(t, err, "")
|
2018-02-22 08:55:42 -05:00
|
|
|
} else {
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.NilError(t, err)
|
2018-02-22 08:55:42 -05:00
|
|
|
}
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal(test.expectedStack, version))
|
2018-02-22 08:55:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type groupVersion struct {
|
|
|
|
name string
|
|
|
|
versions []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeGroups(versions ...groupVersion) *metav1.APIGroupList {
|
|
|
|
groups := make([]metav1.APIGroup, len(versions))
|
|
|
|
for i := range versions {
|
|
|
|
groups[i].Name = versions[i].name
|
|
|
|
for _, v := range versions[i].versions {
|
|
|
|
groups[i].Versions = append(groups[i].Versions, metav1.GroupVersionForDiscovery{Version: v})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &metav1.APIGroupList{
|
|
|
|
Groups: groups,
|
|
|
|
}
|
|
|
|
}
|