Skip to content

Commit 63e1d86

Browse files
committed
fix: fixed resolver errors
1 parent e51ee08 commit 63e1d86

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

gateway/resolver/resolver_test.go

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,13 @@ func TestCreateItem(t *testing.T) {
290290
},
291291
mockSetup: func(runtimeClientMock *mocks.MockWithWatch) {
292292
runtimeClientMock.EXPECT().
293-
Create(mock.Anything, mock.AnythingOfType("*unstructured.Unstructured")).
293+
Create(
294+
mock.Anything,
295+
mock.AnythingOfType("*unstructured.Unstructured"),
296+
mock.MatchedBy(func(opts client.CreateOption) bool {
297+
return true
298+
}),
299+
).
294300
Return(nil)
295301
},
296302
expectedObj: map[string]interface{}{
@@ -315,7 +321,13 @@ func TestCreateItem(t *testing.T) {
315321
},
316322
mockSetup: func(runtimeClientMock *mocks.MockWithWatch) {
317323
runtimeClientMock.EXPECT().
318-
Create(mock.Anything, mock.AnythingOfType("*unstructured.Unstructured")).
324+
Create(
325+
mock.Anything,
326+
mock.AnythingOfType("*unstructured.Unstructured"),
327+
mock.MatchedBy(func(opts client.CreateOption) bool {
328+
return true
329+
}),
330+
).
319331
Return(assert.AnError)
320332
},
321333
expectError: true,
@@ -328,6 +340,35 @@ func TestCreateItem(t *testing.T) {
328340
},
329341
expectError: true,
330342
},
343+
{
344+
name: "create_item_with_dry_run_OK",
345+
args: map[string]interface{}{
346+
resolver.NameArg: "test-object",
347+
resolver.NamespaceArg: "test-namespace",
348+
resolver.DryRunArg: []interface{}{"All"},
349+
"object": map[string]interface{}{
350+
"metadata": map[string]interface{}{
351+
"name": "test-object",
352+
},
353+
},
354+
},
355+
mockSetup: func(runtimeClientMock *mocks.MockWithWatch) {
356+
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+
})).
361+
Return(nil)
362+
},
363+
expectedObj: map[string]interface{}{
364+
"apiVersion": "group/version",
365+
"kind": "kind",
366+
"metadata": map[string]interface{}{
367+
"name": "test-object",
368+
"namespace": "test-namespace",
369+
},
370+
},
371+
},
331372
}
332373

333374
for _, tt := range tests {

0 commit comments

Comments
 (0)