2015-10-30 18:31:01 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors.
|
2015-10-30 18:31:01 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package install
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
|
2016-01-22 05:06:52 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2015-11-13 13:13:55 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
2016-01-13 22:40:56 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
2015-10-30 18:31:01 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/componentconfig"
|
2015-12-21 05:21:26 +00:00
|
|
|
"k8s.io/kubernetes/pkg/runtime"
|
2015-10-30 18:31:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCodec(t *testing.T) {
|
|
|
|
daemonSet := componentconfig.KubeProxyConfiguration{}
|
2016-01-13 22:40:56 +00:00
|
|
|
// We do want to use package registered rather than testapi here, because we
|
|
|
|
// want to test if the package install and package registered work as expected.
|
2015-12-21 05:21:26 +00:00
|
|
|
data, err := runtime.Encode(api.Codecs.LegacyCodec(registered.GroupOrDie(componentconfig.GroupName).GroupVersion), &daemonSet)
|
2015-10-30 18:31:01 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
other := componentconfig.KubeProxyConfiguration{}
|
|
|
|
if err := json.Unmarshal(data, &other); err != nil {
|
|
|
|
t.Fatalf("unexpected error: %v", err)
|
|
|
|
}
|
2016-01-13 22:40:56 +00:00
|
|
|
if other.APIVersion != registered.GroupOrDie(componentconfig.GroupName).GroupVersion.String() || other.Kind != "KubeProxyConfiguration" {
|
2015-10-30 18:31:01 +00:00
|
|
|
t.Errorf("unexpected unmarshalled object %#v", other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInterfacesFor(t *testing.T) {
|
2016-01-13 22:40:56 +00:00
|
|
|
if _, err := registered.GroupOrDie(componentconfig.GroupName).InterfacesFor(componentconfig.SchemeGroupVersion); err == nil {
|
2015-10-30 18:31:01 +00:00
|
|
|
t.Fatalf("unexpected non-error: %v", err)
|
|
|
|
}
|
2016-01-13 22:40:56 +00:00
|
|
|
for i, version := range registered.GroupOrDie(componentconfig.GroupName).GroupVersions {
|
|
|
|
if vi, err := registered.GroupOrDie(componentconfig.GroupName).InterfacesFor(version); err != nil || vi == nil {
|
2015-10-30 18:31:01 +00:00
|
|
|
t.Fatalf("%d: unexpected result: %v", i, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRESTMapper(t *testing.T) {
|
2015-12-08 14:21:04 +00:00
|
|
|
gv := unversioned.GroupVersion{Group: componentconfig.GroupName, Version: "v1alpha1"}
|
2015-11-16 21:24:59 +00:00
|
|
|
proxyGVK := gv.WithKind("KubeProxyConfiguration")
|
2015-11-13 13:13:55 +00:00
|
|
|
|
2016-01-13 22:40:56 +00:00
|
|
|
if gvk, err := registered.GroupOrDie(componentconfig.GroupName).RESTMapper.KindFor(gv.WithResource("kubeproxyconfiguration")); err != nil || gvk != proxyGVK {
|
2015-11-16 21:24:59 +00:00
|
|
|
t.Errorf("unexpected version mapping: %v %v", gvk, err)
|
2015-10-30 18:31:01 +00:00
|
|
|
}
|
|
|
|
|
2016-01-13 22:40:56 +00:00
|
|
|
if m, err := registered.GroupOrDie(componentconfig.GroupName).RESTMapper.RESTMapping(proxyGVK.GroupKind(), ""); err != nil || m.GroupVersionKind != proxyGVK || m.Resource != "kubeproxyconfigurations" {
|
2015-10-30 18:31:01 +00:00
|
|
|
t.Errorf("unexpected version mapping: %#v %v", m, err)
|
|
|
|
}
|
|
|
|
|
2016-01-13 22:40:56 +00:00
|
|
|
for _, version := range registered.GroupOrDie(componentconfig.GroupName).GroupVersions {
|
|
|
|
mapping, err := registered.GroupOrDie(componentconfig.GroupName).RESTMapper.RESTMapping(proxyGVK.GroupKind(), version.Version)
|
2015-10-30 18:31:01 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error: %v", err)
|
2015-11-13 13:13:55 +00:00
|
|
|
continue
|
2015-10-30 18:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if mapping.Resource != "kubeproxyconfigurations" {
|
|
|
|
t.Errorf("incorrect resource name: %#v", mapping)
|
|
|
|
}
|
2015-12-08 18:27:26 +00:00
|
|
|
if mapping.GroupVersionKind.GroupVersion() != version {
|
2015-10-30 18:31:01 +00:00
|
|
|
t.Errorf("incorrect groupVersion: %v", mapping)
|
|
|
|
}
|
|
|
|
|
2016-01-13 22:40:56 +00:00
|
|
|
interfaces, _ := registered.GroupOrDie(componentconfig.GroupName).InterfacesFor(version)
|
2015-12-21 05:21:26 +00:00
|
|
|
if mapping.ObjectConvertor != interfaces.ObjectConvertor {
|
|
|
|
t.Errorf("unexpected: %#v, expected: %#v", mapping, interfaces)
|
2015-10-30 18:31:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|