|
|
|
|
@ -90,6 +90,64 @@ func TestMode1_Create(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMode1_CreateOnUnifiedStorage(t *testing.T) { |
|
|
|
|
ctxCanceled, cancel := context.WithCancel(context.TODO()) |
|
|
|
|
cancel() |
|
|
|
|
|
|
|
|
|
type testCase struct { |
|
|
|
|
name string |
|
|
|
|
input runtime.Object |
|
|
|
|
ctx *context.Context |
|
|
|
|
setupLegacyFn func(m *mock.Mock) |
|
|
|
|
setupStorageFn func(m *mock.Mock) |
|
|
|
|
} |
|
|
|
|
tests := |
|
|
|
|
[]testCase{ |
|
|
|
|
{ |
|
|
|
|
name: "Create on unified storage", |
|
|
|
|
input: exampleObj, |
|
|
|
|
setupStorageFn: func(m *mock.Mock) { |
|
|
|
|
m.On("Create", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(exampleObjNoRV, nil) |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "Create on unified storage works even if parent context is canceled", |
|
|
|
|
input: exampleObj, |
|
|
|
|
ctx: &ctxCanceled, |
|
|
|
|
setupStorageFn: func(m *mock.Mock) { |
|
|
|
|
m.On("Create", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(exampleObjNoRV, nil) |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, tt := range tests { |
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
l := (LegacyStorage)(nil) |
|
|
|
|
s := (Storage)(nil) |
|
|
|
|
m := &mock.Mock{} |
|
|
|
|
|
|
|
|
|
ls := legacyStoreMock{m, l} |
|
|
|
|
us := storageMock{m, s} |
|
|
|
|
|
|
|
|
|
if tt.setupLegacyFn != nil { |
|
|
|
|
tt.setupLegacyFn(m) |
|
|
|
|
} |
|
|
|
|
if tt.setupStorageFn != nil { |
|
|
|
|
tt.setupStorageFn(m) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ctx := context.TODO() |
|
|
|
|
if tt.ctx != nil { |
|
|
|
|
ctx = *tt.ctx |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dw := NewDualWriter(Mode1, ls, us, p, kind) |
|
|
|
|
err := dw.(*DualWriterMode1).createOnUnifiedStorage(ctx, tt.input, func(context.Context, runtime.Object) error { return nil }, tt.input, &metav1.CreateOptions{}) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMode1_Get(t *testing.T) { |
|
|
|
|
type testCase struct { |
|
|
|
|
setupLegacyFn func(m *mock.Mock, name string) |
|
|
|
|
@ -153,6 +211,64 @@ func TestMode1_Get(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMode1_GetFromUnifiedStorage(t *testing.T) { |
|
|
|
|
ctxCanceled, cancel := context.WithCancel(context.TODO()) |
|
|
|
|
cancel() |
|
|
|
|
|
|
|
|
|
type testCase struct { |
|
|
|
|
setupLegacyFn func(m *mock.Mock, name string) |
|
|
|
|
setupStorageFn func(m *mock.Mock, name string) |
|
|
|
|
ctx *context.Context |
|
|
|
|
name string |
|
|
|
|
input string |
|
|
|
|
} |
|
|
|
|
tests := |
|
|
|
|
[]testCase{ |
|
|
|
|
{ |
|
|
|
|
name: "Get from unified storage", |
|
|
|
|
input: "foo", |
|
|
|
|
setupStorageFn: func(m *mock.Mock, name string) { |
|
|
|
|
m.On("Get", mock.Anything, name, mock.Anything).Return(exampleObj, nil) |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "Get from unified storage works even if parent context is canceled", |
|
|
|
|
input: "foo", |
|
|
|
|
ctx: &ctxCanceled, |
|
|
|
|
setupStorageFn: func(m *mock.Mock, name string) { |
|
|
|
|
m.On("Get", mock.Anything, name, mock.Anything).Return(exampleObj, nil) |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, tt := range tests { |
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
l := (LegacyStorage)(nil) |
|
|
|
|
s := (Storage)(nil) |
|
|
|
|
m := &mock.Mock{} |
|
|
|
|
|
|
|
|
|
ls := legacyStoreMock{m, l} |
|
|
|
|
us := storageMock{m, s} |
|
|
|
|
|
|
|
|
|
if tt.setupLegacyFn != nil { |
|
|
|
|
tt.setupLegacyFn(m, tt.input) |
|
|
|
|
} |
|
|
|
|
if tt.setupStorageFn != nil { |
|
|
|
|
tt.setupStorageFn(m, tt.input) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ctx := context.TODO() |
|
|
|
|
if tt.ctx != nil { |
|
|
|
|
ctx = *tt.ctx |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dw := NewDualWriter(Mode1, ls, us, p, kind) |
|
|
|
|
err := dw.(*DualWriterMode1).getFromUnifiedStorage(ctx, exampleObj, tt.input, &metav1.GetOptions{}) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMode1_List(t *testing.T) { |
|
|
|
|
type testCase struct { |
|
|
|
|
setupLegacyFn func(m *mock.Mock) |
|
|
|
|
@ -199,6 +315,62 @@ func TestMode1_List(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMode1_ListFromUnifiedStorage(t *testing.T) { |
|
|
|
|
ctxCanceled, cancel := context.WithCancel(context.TODO()) |
|
|
|
|
cancel() |
|
|
|
|
|
|
|
|
|
type testCase struct { |
|
|
|
|
ctx *context.Context |
|
|
|
|
name string |
|
|
|
|
setupLegacyFn func(m *mock.Mock) |
|
|
|
|
setupStorageFn func(m *mock.Mock) |
|
|
|
|
} |
|
|
|
|
tests := |
|
|
|
|
[]testCase{ |
|
|
|
|
{ |
|
|
|
|
name: "list from unified storage", |
|
|
|
|
setupStorageFn: func(m *mock.Mock) { |
|
|
|
|
m.On("List", mock.Anything, mock.Anything).Return(anotherList, nil) |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "list from unified storage works even if parent context is canceled", |
|
|
|
|
ctx: &ctxCanceled, |
|
|
|
|
setupStorageFn: func(m *mock.Mock) { |
|
|
|
|
m.On("List", mock.Anything, mock.Anything).Return(anotherList, nil) |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, tt := range tests { |
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
l := (LegacyStorage)(nil) |
|
|
|
|
s := (Storage)(nil) |
|
|
|
|
m := &mock.Mock{} |
|
|
|
|
|
|
|
|
|
ls := legacyStoreMock{m, l} |
|
|
|
|
us := storageMock{m, s} |
|
|
|
|
|
|
|
|
|
if tt.setupLegacyFn != nil { |
|
|
|
|
tt.setupLegacyFn(m) |
|
|
|
|
} |
|
|
|
|
if tt.setupStorageFn != nil { |
|
|
|
|
tt.setupStorageFn(m) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ctx := context.TODO() |
|
|
|
|
if tt.ctx != nil { |
|
|
|
|
ctx = *tt.ctx |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dw := NewDualWriter(Mode1, ls, us, p, kind) |
|
|
|
|
|
|
|
|
|
err := dw.(*DualWriterMode1).listFromUnifiedStorage(ctx, &metainternalversion.ListOptions{}, anotherList) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMode1_Delete(t *testing.T) { |
|
|
|
|
type testCase struct { |
|
|
|
|
setupLegacyFn func(m *mock.Mock, name string) |
|
|
|
|
@ -258,6 +430,63 @@ func TestMode1_Delete(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMode1_DeleteFromUnifiedStorage(t *testing.T) { |
|
|
|
|
ctxCanceled, cancel := context.WithCancel(context.TODO()) |
|
|
|
|
cancel() |
|
|
|
|
|
|
|
|
|
type testCase struct { |
|
|
|
|
ctx *context.Context |
|
|
|
|
setupLegacyFn func(m *mock.Mock, name string) |
|
|
|
|
setupStorageFn func(m *mock.Mock, name string) |
|
|
|
|
name string |
|
|
|
|
input string |
|
|
|
|
} |
|
|
|
|
tests := |
|
|
|
|
[]testCase{ |
|
|
|
|
{ |
|
|
|
|
name: "Delete from unified storage", |
|
|
|
|
setupStorageFn: func(m *mock.Mock, input string) { |
|
|
|
|
m.On("Delete", mock.Anything, input, mock.Anything, mock.Anything).Return(exampleObj, false, nil) |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "Delete from unified storage works even if parent context is canceled", |
|
|
|
|
ctx: &ctxCanceled, |
|
|
|
|
setupStorageFn: func(m *mock.Mock, input string) { |
|
|
|
|
m.On("Delete", mock.Anything, input, mock.Anything, mock.Anything).Return(exampleObj, false, nil) |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, tt := range tests { |
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
l := (LegacyStorage)(nil) |
|
|
|
|
s := (Storage)(nil) |
|
|
|
|
m := &mock.Mock{} |
|
|
|
|
|
|
|
|
|
ls := legacyStoreMock{m, l} |
|
|
|
|
us := storageMock{m, s} |
|
|
|
|
|
|
|
|
|
if tt.setupLegacyFn != nil { |
|
|
|
|
tt.setupLegacyFn(m, tt.input) |
|
|
|
|
} |
|
|
|
|
if tt.setupStorageFn != nil { |
|
|
|
|
tt.setupStorageFn(m, tt.input) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ctx := context.TODO() |
|
|
|
|
if tt.ctx != nil { |
|
|
|
|
ctx = *tt.ctx |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dw := NewDualWriter(Mode1, ls, us, p, kind) |
|
|
|
|
|
|
|
|
|
err := dw.(*DualWriterMode1).deleteFromUnifiedStorage(ctx, exampleObj, tt.input, func(ctx context.Context, obj runtime.Object) error { return nil }, &metav1.DeleteOptions{}) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMode1_DeleteCollection(t *testing.T) { |
|
|
|
|
type testCase struct { |
|
|
|
|
input *metav1.DeleteOptions |
|
|
|
|
@ -317,6 +546,65 @@ func TestMode1_DeleteCollection(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMode1_DeleteCollectionFromUnifiedStorage(t *testing.T) { |
|
|
|
|
ctxCanceled, cancel := context.WithCancel(context.TODO()) |
|
|
|
|
cancel() |
|
|
|
|
|
|
|
|
|
type testCase struct { |
|
|
|
|
ctx *context.Context |
|
|
|
|
setupLegacyFn func(m *mock.Mock) |
|
|
|
|
setupStorageFn func(m *mock.Mock) |
|
|
|
|
name string |
|
|
|
|
input *metav1.DeleteOptions |
|
|
|
|
} |
|
|
|
|
tests := |
|
|
|
|
[]testCase{ |
|
|
|
|
{ |
|
|
|
|
name: "Delete Collection from unified storage", |
|
|
|
|
input: &metav1.DeleteOptions{TypeMeta: metav1.TypeMeta{Kind: "foo"}}, |
|
|
|
|
setupStorageFn: func(m *mock.Mock) { |
|
|
|
|
m.On("DeleteCollection", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(exampleObj, nil) |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "Delete Collection from unified storage works even if parent context is canceled", |
|
|
|
|
input: &metav1.DeleteOptions{TypeMeta: metav1.TypeMeta{Kind: "foo"}}, |
|
|
|
|
ctx: &ctxCanceled, |
|
|
|
|
setupStorageFn: func(m *mock.Mock) { |
|
|
|
|
m.On("DeleteCollection", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(exampleObj, nil) |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, tt := range tests { |
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
l := (LegacyStorage)(nil) |
|
|
|
|
s := (Storage)(nil) |
|
|
|
|
m := &mock.Mock{} |
|
|
|
|
|
|
|
|
|
ls := legacyStoreMock{m, l} |
|
|
|
|
us := storageMock{m, s} |
|
|
|
|
|
|
|
|
|
if tt.setupLegacyFn != nil { |
|
|
|
|
tt.setupLegacyFn(m) |
|
|
|
|
} |
|
|
|
|
if tt.setupStorageFn != nil { |
|
|
|
|
tt.setupStorageFn(m) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ctx := context.TODO() |
|
|
|
|
if tt.ctx != nil { |
|
|
|
|
ctx = *tt.ctx |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dw := NewDualWriter(Mode1, ls, us, p, kind) |
|
|
|
|
|
|
|
|
|
err := dw.(*DualWriterMode1).deleteCollectionFromUnifiedStorage(ctx, exampleObj, func(ctx context.Context, obj runtime.Object) error { return nil }, tt.input, &metainternalversion.ListOptions{}) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMode1_Update(t *testing.T) { |
|
|
|
|
type testCase struct { |
|
|
|
|
setupLegacyFn func(m *mock.Mock, input string) |
|
|
|
|
@ -391,3 +679,73 @@ func TestMode1_Update(t *testing.T) { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMode1_UpdateOnUnifiedStorage(t *testing.T) { |
|
|
|
|
ctxCanceled, cancel := context.WithCancel(context.TODO()) |
|
|
|
|
cancel() |
|
|
|
|
|
|
|
|
|
type testCase struct { |
|
|
|
|
ctx *context.Context |
|
|
|
|
setupLegacyFn func(m *mock.Mock, input string) |
|
|
|
|
setupStorageFn func(m *mock.Mock, input string) |
|
|
|
|
setupGetFn func(m *mock.Mock, input string) |
|
|
|
|
name string |
|
|
|
|
input string |
|
|
|
|
} |
|
|
|
|
tests := |
|
|
|
|
[]testCase{ |
|
|
|
|
{ |
|
|
|
|
name: "Update on unified storage", |
|
|
|
|
input: "foo", |
|
|
|
|
setupStorageFn: func(m *mock.Mock, input string) { |
|
|
|
|
m.On("Update", mock.Anything, input, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(anotherObj, false, nil) |
|
|
|
|
}, |
|
|
|
|
setupGetFn: func(m *mock.Mock, input string) { |
|
|
|
|
m.On("Get", mock.Anything, input, mock.Anything).Return(exampleObj, nil) |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "Update on unified storage works even if parent context is canceled", |
|
|
|
|
ctx: &ctxCanceled, |
|
|
|
|
input: "foo", |
|
|
|
|
setupStorageFn: func(m *mock.Mock, input string) { |
|
|
|
|
m.On("Update", mock.Anything, input, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(anotherObj, false, nil) |
|
|
|
|
}, |
|
|
|
|
setupGetFn: func(m *mock.Mock, input string) { |
|
|
|
|
m.On("Get", mock.Anything, input, mock.Anything).Return(exampleObj, nil) |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, tt := range tests { |
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
l := (LegacyStorage)(nil) |
|
|
|
|
s := (Storage)(nil) |
|
|
|
|
m := &mock.Mock{} |
|
|
|
|
|
|
|
|
|
ls := legacyStoreMock{m, l} |
|
|
|
|
us := storageMock{m, s} |
|
|
|
|
|
|
|
|
|
if tt.setupLegacyFn != nil { |
|
|
|
|
tt.setupLegacyFn(m, tt.input) |
|
|
|
|
} |
|
|
|
|
if tt.setupStorageFn != nil { |
|
|
|
|
tt.setupStorageFn(m, tt.input) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if tt.setupGetFn != nil { |
|
|
|
|
tt.setupGetFn(m, tt.input) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ctx := context.TODO() |
|
|
|
|
if tt.ctx != nil { |
|
|
|
|
ctx = *tt.ctx |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dw := NewDualWriter(Mode1, ls, us, p, kind) |
|
|
|
|
|
|
|
|
|
err := dw.(*DualWriterMode1).updateOnUnifiedStorage(ctx, exampleObj, tt.input, updatedObjInfoObj{}, func(ctx context.Context, obj runtime.Object) error { return nil }, func(ctx context.Context, obj, old runtime.Object) error { return nil }, false, &metav1.UpdateOptions{}) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|