Merge pull request #51601 from caesarxuchao/minor-test-fix

Automatic merge from submit-queue (batch tested with PRs 51601, 52153, 52364, 52362, 52342)

Minor fixes to validation test

Some test cases confuse the new object with the old object. This PR fixed that. Also added a test to verify that deletionTimestamp cannot be added (via the REST endpoints).
This commit is contained in:
Kubernetes Submit Queue 2017-09-13 09:30:01 -07:00 committed by GitHub
commit a91c8939b7

View File

@ -5910,8 +5910,8 @@ func TestValidatePodUpdate(t *testing.T) {
)
tests := []struct {
a api.Pod
b api.Pod
new api.Pod
old api.Pod
err string
test string
}{
@ -5993,6 +5993,35 @@ func TestValidatePodUpdate(t *testing.T) {
},
},
"may not add or remove containers",
"less containers",
},
{
api.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
},
Spec: api.PodSpec{
Containers: []api.Container{
{
Image: "foo:V1",
},
{
Image: "bar:V2",
},
},
},
},
api.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Spec: api.PodSpec{
Containers: []api.Container{
{
Image: "foo:V2",
},
},
},
},
"may not add or remove containers",
"more containers",
},
{
@ -6034,7 +6063,19 @@ func TestValidatePodUpdate(t *testing.T) {
Spec: api.PodSpec{Containers: []api.Container{{Image: "foo:V1"}}},
},
"",
"deletion timestamp filled out",
"deletion timestamp removed",
},
{
api.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "foo", DeletionTimestamp: &now},
Spec: api.PodSpec{Containers: []api.Container{{Image: "foo:V1"}}},
},
api.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Spec: api.PodSpec{Containers: []api.Container{{Image: "foo:V1"}}},
},
"metadata.deletionTimestamp",
"deletion timestamp added",
},
{
api.Pod{
@ -6046,7 +6087,7 @@ func TestValidatePodUpdate(t *testing.T) {
Spec: api.PodSpec{Containers: []api.Container{{Image: "foo:V1"}}},
},
"metadata.deletionGracePeriodSeconds",
"deletion grace period seconds cleared",
"deletion grace period seconds changed",
},
{
api.Pod{
@ -6502,13 +6543,13 @@ func TestValidatePodUpdate(t *testing.T) {
api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", Annotations: map[string]string{api.MirrorPodAnnotationKey: ""}}, Spec: api.PodSpec{NodeName: "foo"}},
api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}, Spec: api.PodSpec{NodeName: "foo"}},
"metadata.annotations[kubernetes.io/config.mirror]",
"removed mirror pod annotation",
"added mirror pod annotation",
},
{
api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}, Spec: api.PodSpec{NodeName: "foo"}},
api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", Annotations: map[string]string{api.MirrorPodAnnotationKey: ""}}, Spec: api.PodSpec{NodeName: "foo"}},
"metadata.annotations[kubernetes.io/config.mirror]",
"added mirror pod annotation",
"removed mirror pod annotation",
},
{
api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", Annotations: map[string]string{api.MirrorPodAnnotationKey: "foo"}}, Spec: api.PodSpec{NodeName: "foo"}},
@ -6563,16 +6604,16 @@ func TestValidatePodUpdate(t *testing.T) {
}
for _, test := range tests {
test.a.ObjectMeta.ResourceVersion = "1"
test.b.ObjectMeta.ResourceVersion = "1"
errs := ValidatePodUpdate(&test.a, &test.b)
test.new.ObjectMeta.ResourceVersion = "1"
test.old.ObjectMeta.ResourceVersion = "1"
errs := ValidatePodUpdate(&test.new, &test.old)
if test.err == "" {
if len(errs) != 0 {
t.Errorf("unexpected invalid: %s (%+v)\nA: %+v\nB: %+v", test.test, errs, test.a, test.b)
t.Errorf("unexpected invalid: %s (%+v)\nA: %+v\nB: %+v", test.test, errs, test.new, test.old)
}
} else {
if len(errs) == 0 {
t.Errorf("unexpected valid: %s\nA: %+v\nB: %+v", test.test, test.a, test.b)
t.Errorf("unexpected valid: %s\nA: %+v\nB: %+v", test.test, test.new, test.old)
} else if actualErr := errs.ToAggregate().Error(); !strings.Contains(actualErr, test.err) {
t.Errorf("unexpected error message: %s\nExpected error: %s\nActual error: %s", test.test, test.err, actualErr)
}