in pkg/kubelet/config/commont_test.go, remove check for v1beta1, add test cases for all registered version

This commit is contained in:
Chao Xu 2015-06-03 16:07:00 -07:00
parent b61658d064
commit 97b29c7fe6

View File

@ -21,6 +21,7 @@ import (
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/registered"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/securitycontext"
@ -56,11 +57,6 @@ func TestDecodeSinglePod(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}
parsed, podOut, err := tryDecodeSinglePod(json, noDefault)
if testapi.Version() == "v1beta1" {
// v1beta1 conversion leaves empty lists that should be nil
podOut.Spec.Containers[0].Resources.Limits = nil
podOut.Spec.Containers[0].Resources.Requests = nil
}
if !parsed {
t.Errorf("expected to have parsed file: (%s)", string(json))
}
@ -71,24 +67,26 @@ func TestDecodeSinglePod(t *testing.T) {
t.Errorf("expected:\n%#v\ngot:\n%#v\n%s", pod, podOut, string(json))
}
externalPod, err := testapi.Converter().ConvertToVersion(pod, "v1beta3")
if err != nil {
t.Errorf("unexpected error: %v", err)
}
yaml, err := yaml.Marshal(externalPod)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
for _, version := range registered.RegisteredVersions {
externalPod, err := testapi.Converter().ConvertToVersion(pod, version)
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))
}
if err != nil {
t.Errorf("unexpected error: %v (%s)", err, string(yaml))
}
if !reflect.DeepEqual(pod, podOut) {
t.Errorf("expected:\n%#v\ngot:\n%#v\n%s", pod, podOut, string(yaml))
parsed, podOut, err = tryDecodeSinglePod(yaml, noDefault)
if !parsed {
t.Errorf("expected to have parsed file: (%s)", string(yaml))
}
if err != nil {
t.Errorf("unexpected error: %v (%s)", err, string(yaml))
}
if !reflect.DeepEqual(pod, podOut) {
t.Errorf("expected:\n%#v\ngot:\n%#v\n%s", pod, podOut, string(yaml))
}
}
}
@ -137,23 +135,25 @@ func TestDecodePodList(t *testing.T) {
t.Errorf("expected:\n%#v\ngot:\n%#v\n%s", podList, &podListOut, string(json))
}
externalPodList, err := testapi.Converter().ConvertToVersion(podList, "v1beta3")
if err != nil {
t.Errorf("unexpected error: %v", err)
}
yaml, err := yaml.Marshal(externalPodList)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
for _, version := range registered.RegisteredVersions {
externalPodList, err := testapi.Converter().ConvertToVersion(podList, version)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
yaml, err := yaml.Marshal(externalPodList)
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))
}
if err != nil {
t.Errorf("unexpected error: %v (%s)", err, string(yaml))
}
if !reflect.DeepEqual(podList, &podListOut) {
t.Errorf("expected:\n%#v\ngot:\n%#v\n%s", pod, &podListOut, string(yaml))
parsed, podListOut, err = tryDecodePodList(yaml, noDefault)
if !parsed {
t.Errorf("expected to have parsed file: (%s)", string(yaml))
}
if err != nil {
t.Errorf("unexpected error: %v (%s)", err, string(yaml))
}
if !reflect.DeepEqual(podList, &podListOut) {
t.Errorf("expected:\n%#v\ngot:\n%#v\n%s", pod, &podListOut, string(yaml))
}
}
}