Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Reset resource version if fake client Create call failed #919

Merged
merged 1 commit into from
May 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/client/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ func (t versionedTracker) Create(gvr schema.GroupVersionResource, obj runtime.Ob
return apierrors.NewBadRequest("resourceVersion can not be set for Create requests")
}
accessor.SetResourceVersion("1")
return t.ObjectTracker.Create(gvr, obj, ns)
if err := t.ObjectTracker.Create(gvr, obj, ns); err != nil {
accessor.SetResourceVersion("")
return err
}
return nil
}

func (t versionedTracker) Update(gvr schema.GroupVersionResource, obj runtime.Object, ns string) error {
Expand Down
8 changes: 8 additions & 0 deletions pkg/client/fake/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ var _ = Describe("Fake client", func() {
Expect(apierrors.IsBadRequest(err)).To(BeTrue())
})

It("should not change the submitted object if Create failed", func() {
By("Trying to create an existing configmap")
submitted := cm.DeepCopy()
err := cl.Create(context.Background(), submitted)
Expect(apierrors.IsAlreadyExists(err)).To(BeTrue())
Expect(submitted).To(Equal(cm))
})

It("should error on Create with empty Name", func() {
By("Creating a new configmap")
newcm := &corev1.ConfigMap{
Expand Down