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

Function Test_Mock_On_WithPtrArgMatcher

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

Source from the content-addressed store, hash-verified

338}
339
340func Test_Mock_On_WithPtrArgMatcher(t *testing.T) {
341 t.Parallel()
342
343 var mockedService TestExampleImplementation
344
345 mockedService.On("TheExampleMethod3",
346 MatchedBy(func(a *ExampleType) bool { return a != nil && a.ran == true }),
347 ).Return(nil)
348
349 mockedService.On("TheExampleMethod3",
350 MatchedBy(func(a *ExampleType) bool { return a != nil && a.ran == false }),
351 ).Return(errors.New("error"))
352
353 mockedService.On("TheExampleMethod3",
354 MatchedBy(func(a *ExampleType) bool { return a == nil }),
355 ).Return(errors.New("error2"))
356
357 assert.Equal(t, mockedService.TheExampleMethod3(&ExampleType{true}), nil)
358 assert.EqualError(t, mockedService.TheExampleMethod3(&ExampleType{false}), "error")
359 assert.EqualError(t, mockedService.TheExampleMethod3(nil), "error2")
360}
361
362func Test_Mock_On_WithFuncArgMatcher(t *testing.T) {
363 t.Parallel()

Callers

nothing calls this directly

Calls 6

TheExampleMethod3Method · 0.95
EqualFunction · 0.92
EqualErrorFunction · 0.92
MatchedByFunction · 0.85
ReturnMethod · 0.80
OnMethod · 0.45

Tested by

no test coverage detected