Commit f8ed5c36 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #40080 from soltysh/fix_resttest

Automatic merge from submit-queue Fix resttest Update action when AllowUnconditionalUpdate is false Currently our storage Update test assumes that AllowUncoditionalUpdate returns true, and in testUpdateRejectsMismatchedNamespace updates the same object it's passing to create. This results in errors when trying to update that object, due to resourceVersion not being set to a proper value. This patch modifes this so that the update is executed on a stored object, which will have correct values set. @deads2k ptal @kubernetes/sig-api-machinery-misc fyi
parents 0144fae6 aec417a5
...@@ -169,7 +169,7 @@ func (t *Tester) TestUpdate(valid runtime.Object, createFn CreateFunc, getFn Get ...@@ -169,7 +169,7 @@ func (t *Tester) TestUpdate(valid runtime.Object, createFn CreateFunc, getFn Get
t.testUpdateFailsOnVersionTooOld(copyOrDie(valid), createFn, getFn) t.testUpdateFailsOnVersionTooOld(copyOrDie(valid), createFn, getFn)
t.testUpdateOnNotFound(copyOrDie(valid)) t.testUpdateOnNotFound(copyOrDie(valid))
if !t.clusterScope { if !t.clusterScope {
t.testUpdateRejectsMismatchedNamespace(copyOrDie(valid), createFn) t.testUpdateRejectsMismatchedNamespace(copyOrDie(valid), createFn, getFn)
} }
t.testUpdateInvokesValidation(copyOrDie(valid), createFn, invalidUpdateFn...) t.testUpdateInvokesValidation(copyOrDie(valid), createFn, invalidUpdateFn...)
t.testUpdateWithWrongUID(copyOrDie(valid), createFn, getFn) t.testUpdateWithWrongUID(copyOrDie(valid), createFn, getFn)
...@@ -686,7 +686,7 @@ func (t *Tester) testUpdateOnNotFound(obj runtime.Object) { ...@@ -686,7 +686,7 @@ func (t *Tester) testUpdateOnNotFound(obj runtime.Object) {
} }
} }
func (t *Tester) testUpdateRejectsMismatchedNamespace(obj runtime.Object, createFn CreateFunc) { func (t *Tester) testUpdateRejectsMismatchedNamespace(obj runtime.Object, createFn CreateFunc, getFn GetFunc) {
ctx := t.TestContext() ctx := t.TestContext()
foo := copyOrDie(obj) foo := copyOrDie(obj)
...@@ -695,11 +695,16 @@ func (t *Tester) testUpdateRejectsMismatchedNamespace(obj runtime.Object, create ...@@ -695,11 +695,16 @@ func (t *Tester) testUpdateRejectsMismatchedNamespace(obj runtime.Object, create
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
objectMeta := t.getObjectMetaOrFail(obj) storedFoo, err := getFn(ctx, foo)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
objectMeta := t.getObjectMetaOrFail(storedFoo)
objectMeta.Name = t.namer(1) objectMeta.Name = t.namer(1)
objectMeta.Namespace = "not-default" objectMeta.Namespace = "not-default"
obj, updated, err := t.storage.(rest.Updater).Update(t.TestContext(), "foo1", rest.DefaultUpdatedObjectInfo(obj, api.Scheme)) obj, updated, err := t.storage.(rest.Updater).Update(t.TestContext(), "foo1", rest.DefaultUpdatedObjectInfo(storedFoo, api.Scheme))
if obj != nil || updated { if obj != nil || updated {
t.Errorf("expected nil object and not updated") t.Errorf("expected nil object and not updated")
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment