Update tests to handle codec changes

This commit is contained in:
Clayton Coleman
2016-01-22 00:06:52 -05:00
parent 2fd38a7dc0
commit 33085c0cf2
34 changed files with 147 additions and 181 deletions

View File

@@ -24,9 +24,10 @@ import (
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apimachinery/registered"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/securitycontext"
"github.com/ghodss/yaml"
//"github.com/ghodss/yaml"
)
func noDefault(*api.Pod) error { return nil }
@@ -56,7 +57,7 @@ func TestDecodeSinglePod(t *testing.T) {
SecurityContext: &api.PodSecurityContext{},
},
}
json, err := testapi.Default.Codec().Encode(pod)
json, err := runtime.Encode(testapi.Default.Codec(), pod)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@@ -72,15 +73,12 @@ func TestDecodeSinglePod(t *testing.T) {
}
for _, gv := range registered.EnabledVersionsForGroup(api.GroupName) {
externalPod, err := testapi.Default.Converter().ConvertToVersion(pod, gv.String())
s, _ := api.Codecs.SerializerForFileExtension("yaml")
encoder := api.Codecs.EncoderForVersion(s, gv)
yaml, err := runtime.Encode(encoder, pod)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
yaml, err := yaml.Marshal(externalPod)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
parsed, podOut, err = tryDecodeSinglePod(yaml, noDefault)
if !parsed {
t.Errorf("expected to have parsed file: (%s)", string(yaml))
@@ -122,7 +120,7 @@ func TestDecodePodList(t *testing.T) {
podList := &api.PodList{
Items: []api.Pod{*pod},
}
json, err := testapi.Default.Codec().Encode(podList)
json, err := runtime.Encode(testapi.Default.Codec(), podList)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@@ -138,21 +136,21 @@ func TestDecodePodList(t *testing.T) {
}
for _, gv := range registered.EnabledVersionsForGroup(api.GroupName) {
externalPodList, err := testapi.Default.Converter().ConvertToVersion(podList, gv.String())
if err != nil {
t.Errorf("unexpected error: %v", err)
}
yaml, err := yaml.Marshal(externalPodList)
s, _ := api.Codecs.SerializerForFileExtension("yaml")
encoder := api.Codecs.EncoderForVersion(s, gv)
yaml, err := runtime.Encode(encoder, podList)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
parsed, podListOut, err = tryDecodePodList(yaml, noDefault)
if !parsed {
t.Errorf("expected to have parsed file: (%s)", string(yaml))
t.Errorf("expected to have parsed file: (%s): %v", string(yaml), err)
continue
}
if err != nil {
t.Errorf("unexpected error: %v (%s)", err, string(yaml))
continue
}
if !reflect.DeepEqual(podList, &podListOut) {
t.Errorf("expected:\n%#v\ngot:\n%#v\n%s", pod, &podListOut, string(yaml))