MCPcopy
hub / github.com/stretchr/testify / Test_Mock_On_WithFuncArgMatcher

Function Test_Mock_On_WithFuncArgMatcher

mock/mock_test.go:362–386  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

360}
361
362func Test_Mock_On_WithFuncArgMatcher(t *testing.T) {
363 t.Parallel()
364
365 var mockedService TestExampleImplementation
366
367 fixture1, fixture2 := errors.New("fixture1"), errors.New("fixture2")
368
369 mockedService.On("TheExampleMethodFunc",
370 MatchedBy(func(a func(string) error) bool { return a != nil && a("string") == fixture1 }),
371 ).Return(errors.New("fixture1"))
372
373 mockedService.On("TheExampleMethodFunc",
374 MatchedBy(func(a func(string) error) bool { return a != nil && a("string") == fixture2 }),
375 ).Return(errors.New("fixture2"))
376
377 mockedService.On("TheExampleMethodFunc",
378 MatchedBy(func(a func(string) error) bool { return a == nil }),
379 ).Return(errors.New("fixture3"))
380
381 assert.EqualError(t, mockedService.TheExampleMethodFunc(
382 func(string) error { return fixture1 }), "fixture1")
383 assert.EqualError(t, mockedService.TheExampleMethodFunc(
384 func(string) error { return fixture2 }), "fixture2")
385 assert.EqualError(t, mockedService.TheExampleMethodFunc(nil), "fixture3")
386}
387
388func Test_Mock_On_WithInterfaceArgMatcher(t *testing.T) {
389 t.Parallel()

Callers

nothing calls this directly

Calls 5

TheExampleMethodFuncMethod · 0.95
EqualErrorFunction · 0.92
MatchedByFunction · 0.85
ReturnMethod · 0.80
OnMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…