Cleanup: remove deprecated fields the proper way
This commit is contained in:
112
pkg/api/conversion_test.go
Normal file
112
pkg/api/conversion_test.go
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All rights reserved.
|
||||
|
||||
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 api
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
|
||||
)
|
||||
|
||||
func TestEnvConversion(t *testing.T) {
|
||||
nonCanonical := []v1beta1.EnvVar{
|
||||
{Key: "EV"},
|
||||
{Key: "EV", Name: "EX"},
|
||||
}
|
||||
canonical := []EnvVar{
|
||||
{Name: "EV"},
|
||||
{Name: "EX"},
|
||||
}
|
||||
for i := range nonCanonical {
|
||||
var got EnvVar
|
||||
err := Convert(&nonCanonical[i], &got)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if e, a := canonical[i], got; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("expected %v, got %v", e, a)
|
||||
}
|
||||
}
|
||||
|
||||
// Test conversion the other way, too.
|
||||
for i := range canonical {
|
||||
var got v1beta1.EnvVar
|
||||
err := Convert(&canonical[i], &got)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if e, a := canonical[i].Name, got.Key; e != a {
|
||||
t.Errorf("expected %v, got %v", e, a)
|
||||
}
|
||||
if e, a := canonical[i].Name, got.Name; e != a {
|
||||
t.Errorf("expected %v, got %v", e, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolumeMountConversionToOld(t *testing.T) {
|
||||
table := []struct {
|
||||
in VolumeMount
|
||||
out v1beta1.VolumeMount
|
||||
}{
|
||||
{
|
||||
in: VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
||||
out: v1beta1.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/foo", ReadOnly: true},
|
||||
},
|
||||
}
|
||||
for _, item := range table {
|
||||
got := v1beta1.VolumeMount{}
|
||||
err := Convert(&item.in, &got)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
continue
|
||||
}
|
||||
if e, a := item.out, got; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("Expected: %#v, got %#v", e, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolumeMountConversionToNew(t *testing.T) {
|
||||
table := []struct {
|
||||
in v1beta1.VolumeMount
|
||||
out VolumeMount
|
||||
}{
|
||||
{
|
||||
in: v1beta1.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
||||
out: VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
||||
}, {
|
||||
in: v1beta1.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/bar", ReadOnly: true},
|
||||
out: VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
|
||||
}, {
|
||||
in: v1beta1.VolumeMount{Name: "foo", Path: "/dev/bar", ReadOnly: true},
|
||||
out: VolumeMount{Name: "foo", MountPath: "/dev/bar", ReadOnly: true},
|
||||
},
|
||||
}
|
||||
for _, item := range table {
|
||||
got := VolumeMount{}
|
||||
err := Convert(&item.in, &got)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
continue
|
||||
}
|
||||
if e, a := item.out, got; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("Expected: %#v, got %#v", e, a)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user