mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
storage: etcd: TestConditionalDelete: use sub-tests
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
This commit is contained in:
parent
dbb00694f6
commit
7729691f5c
@ -341,32 +341,37 @@ func TestConditionalDelete(t *testing.T) {
|
|||||||
key, storedObj := testPropogateStore(ctx, t, store, &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", UID: "A"}})
|
key, storedObj := testPropogateStore(ctx, t, store, &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", UID: "A"}})
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
precondition *storage.Preconditions
|
precondition *storage.Preconditions
|
||||||
expectInvalidObjErr bool
|
expectInvalidObjErr bool
|
||||||
}{{ // test conditional delete with UID match
|
}{{
|
||||||
|
name: "test conditional delete with UID match",
|
||||||
precondition: storage.NewUIDPreconditions("A"),
|
precondition: storage.NewUIDPreconditions("A"),
|
||||||
expectInvalidObjErr: false,
|
expectInvalidObjErr: false,
|
||||||
}, { // test conditional delete with UID mismatch
|
}, {
|
||||||
|
name: "test conditional delete with UID mismatch",
|
||||||
precondition: storage.NewUIDPreconditions("B"),
|
precondition: storage.NewUIDPreconditions("B"),
|
||||||
expectInvalidObjErr: true,
|
expectInvalidObjErr: true,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
for i, tt := range tests {
|
for _, tt := range tests {
|
||||||
out := &example.Pod{}
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
err := store.Delete(ctx, key, out, tt.precondition, storage.ValidateAllObjectFunc, nil)
|
out := &example.Pod{}
|
||||||
if tt.expectInvalidObjErr {
|
err := store.Delete(ctx, key, out, tt.precondition, storage.ValidateAllObjectFunc, nil)
|
||||||
if err == nil || !storage.IsInvalidObj(err) {
|
if tt.expectInvalidObjErr {
|
||||||
t.Errorf("#%d: expecting invalid UID error, but get: %s", i, err)
|
if err == nil || !storage.IsInvalidObj(err) {
|
||||||
|
t.Errorf("%s: expecting invalid UID error, but get: %s", tt.name, err)
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
continue
|
if err != nil {
|
||||||
}
|
t.Fatalf("%s: Delete failed: %v", tt.name, err)
|
||||||
if err != nil {
|
}
|
||||||
t.Fatalf("Delete failed: %v", err)
|
if !reflect.DeepEqual(storedObj, out) {
|
||||||
}
|
t.Errorf("%s: pod want=%#v, get=%#v", tt.name, storedObj, out)
|
||||||
if !reflect.DeepEqual(storedObj, out) {
|
}
|
||||||
t.Errorf("#%d: pod want=%#v, get=%#v", i, storedObj, out)
|
key, storedObj = testPropogateStore(ctx, t, store, &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", UID: "A"}})
|
||||||
}
|
})
|
||||||
key, storedObj = testPropogateStore(ctx, t, store, &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", UID: "A"}})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user