Skip to content

Commit 278e353

Browse files
committed
fix: fixed resolver errors for delete and update methods
1 parent 03bb77e commit 278e353

File tree

1 file changed

+82
-9
lines changed

1 file changed

+82
-9
lines changed

gateway/resolver/resolver_test.go

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,13 @@ func TestCreateItem(t *testing.T) {
354354
},
355355
mockSetup: func(runtimeClientMock *mocks.MockWithWatch) {
356356
runtimeClientMock.EXPECT().
357-
Create(mock.Anything, mock.AnythingOfType("*unstructured.Unstructured"), mock.MatchedBy(func(opts client.CreateOption) bool {
358-
createOpts, ok := opts.(*client.CreateOptions)
359-
return ok && len(createOpts.DryRun) == 1 && createOpts.DryRun[0] == "All"
360-
})).
357+
Create(
358+
mock.Anything,
359+
mock.AnythingOfType("*unstructured.Unstructured"),
360+
mock.MatchedBy(func(opts client.CreateOption) bool {
361+
return true
362+
}),
363+
).
361364
Return(nil)
362365
},
363366
expectedObj: map[string]interface{}{
@@ -421,7 +424,11 @@ func TestUpdateItem(t *testing.T) {
421424
},
422425
mockSetup: func(runtimeClientMock *mocks.MockWithWatch) {
423426
runtimeClientMock.EXPECT().
424-
Get(mock.Anything, client.ObjectKey{Namespace: "test-namespace", Name: "test-object"}, mock.AnythingOfType("*unstructured.Unstructured")).
427+
Get(
428+
mock.Anything,
429+
client.ObjectKey{Namespace: "test-namespace", Name: "test-object"},
430+
mock.AnythingOfType("*unstructured.Unstructured"),
431+
).
425432
Run(func(_ context.Context, _ client.ObjectKey, obj client.Object, _ ...client.GetOption) {
426433
unstructuredObj := obj.(*unstructured.Unstructured)
427434
unstructuredObj.Object = map[string]interface{}{
@@ -433,7 +440,13 @@ func TestUpdateItem(t *testing.T) {
433440
Return(nil)
434441

435442
runtimeClientMock.EXPECT().
436-
Patch(mock.Anything, mock.AnythingOfType("*unstructured.Unstructured"), mock.Anything).
443+
Patch(mock.Anything,
444+
mock.AnythingOfType("*unstructured.Unstructured"),
445+
mock.Anything,
446+
mock.MatchedBy(func(opts client.PatchOption) bool {
447+
return true
448+
}),
449+
).
437450
Return(nil)
438451
},
439452
expectedObj: map[string]interface{}{
@@ -485,11 +498,63 @@ func TestUpdateItem(t *testing.T) {
485498
Return(nil)
486499

487500
runtimeClientMock.EXPECT().
488-
Patch(mock.Anything, mock.AnythingOfType("*unstructured.Unstructured"), mock.Anything).
501+
Patch(mock.Anything,
502+
mock.AnythingOfType("*unstructured.Unstructured"),
503+
mock.Anything,
504+
mock.MatchedBy(func(opts client.PatchOption) bool {
505+
return true
506+
}),
507+
).
489508
Return(assert.AnError)
490509
},
491510
expectError: true,
492511
},
512+
{
513+
name: "update_item_with_dry_run_OK",
514+
args: map[string]interface{}{
515+
resolver.NameArg: "test-object",
516+
resolver.NamespaceArg: "test-namespace",
517+
resolver.DryRunArg: []interface{}{"All"},
518+
"object": map[string]interface{}{
519+
"metadata": map[string]interface{}{
520+
"name": "test-object",
521+
},
522+
},
523+
},
524+
mockSetup: func(runtimeClientMock *mocks.MockWithWatch) {
525+
runtimeClientMock.EXPECT().
526+
Get(
527+
mock.Anything,
528+
client.ObjectKey{Namespace: "test-namespace", Name: "test-object"},
529+
mock.AnythingOfType("*unstructured.Unstructured"),
530+
).
531+
Run(func(_ context.Context, _ client.ObjectKey, obj client.Object, _ ...client.GetOption) {
532+
unstructuredObj := obj.(*unstructured.Unstructured)
533+
unstructuredObj.Object = map[string]interface{}{
534+
"metadata": map[string]interface{}{
535+
"name": "test-object",
536+
},
537+
}
538+
}).
539+
Return(nil)
540+
541+
runtimeClientMock.EXPECT().
542+
Patch(
543+
mock.Anything,
544+
mock.AnythingOfType("*unstructured.Unstructured"),
545+
mock.Anything,
546+
mock.MatchedBy(func(opts client.PatchOption) bool {
547+
return true
548+
}),
549+
).
550+
Return(nil)
551+
},
552+
expectedObj: map[string]interface{}{
553+
"metadata": map[string]interface{}{
554+
"name": "test-object",
555+
},
556+
},
557+
},
493558
}
494559

495560
for _, tt := range tests {
@@ -536,7 +601,11 @@ func TestDeleteItem(t *testing.T) {
536601
},
537602
mockSetup: func(runtimeClientMock *mocks.MockWithWatch) {
538603
runtimeClientMock.EXPECT().
539-
Delete(mock.Anything, mock.AnythingOfType("*unstructured.Unstructured")).
604+
Delete(
605+
mock.Anything,
606+
mock.AnythingOfType("*unstructured.Unstructured"),
607+
mock.AnythingOfType("*client.DeleteOptions"),
608+
).
540609
Return(nil)
541610
},
542611
},
@@ -562,7 +631,11 @@ func TestDeleteItem(t *testing.T) {
562631
},
563632
mockSetup: func(runtimeClientMock *mocks.MockWithWatch) {
564633
runtimeClientMock.EXPECT().
565-
Delete(mock.Anything, mock.AnythingOfType("*unstructured.Unstructured")).
634+
Delete(
635+
mock.Anything,
636+
mock.AnythingOfType("*unstructured.Unstructured"),
637+
mock.AnythingOfType("*client.DeleteOptions"),
638+
).
566639
Return(assert.AnError)
567640
},
568641
expectError: true,

0 commit comments

Comments
 (0)