Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 9 additions & 22 deletions mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
"time"

"github.com/davecgh/go-spew/spew"
"github.com/pmezard/go-difflib/difflib"

Check failure on line 15 in mock/mock.go

View workflow job for this annotation

GitHub Actions / build (oldstable)

cannot find module providing package github.com/pmezard/go-difflib/difflib: import lookup disabled by -mod=vendor

Check failure on line 15 in mock/mock.go

View workflow job for this annotation

GitHub Actions / build (stable)

cannot find module providing package github.com/pmezard/go-difflib/difflib: import lookup disabled by -mod=vendor

Check failure on line 15 in mock/mock.go

View workflow job for this annotation

GitHub Actions / test (1.22)

cannot find module providing package github.com/pmezard/go-difflib/difflib: import lookup disabled by -mod=vendor

Check failure on line 15 in mock/mock.go

View workflow job for this annotation

GitHub Actions / test (1.23)

cannot find module providing package github.com/pmezard/go-difflib/difflib: import lookup disabled by -mod=vendor

Check failure on line 15 in mock/mock.go

View workflow job for this annotation

GitHub Actions / build (oldstable)

cannot find module providing package github.com/pmezard/go-difflib/difflib: import lookup disabled by -mod=vendor

Check failure on line 15 in mock/mock.go

View workflow job for this annotation

GitHub Actions / test (1.22)

cannot find module providing package github.com/pmezard/go-difflib/difflib: import lookup disabled by -mod=vendor

Check failure on line 15 in mock/mock.go

View workflow job for this annotation

GitHub Actions / test (1.23)

cannot find module providing package github.com/pmezard/go-difflib/difflib: import lookup disabled by -mod=vendor
"github.com/stretchr/objx"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/internal/difflib"
)

// regex for GCCGO functions
Expand Down Expand Up @@ -603,12 +604,11 @@
h.Helper()
}
for _, obj := range testObjects {
m, ok := obj.(assertExpectationiser)
if !ok {
t.Errorf("Invalid test object type %T. Expected reference to a mock.Mock, eg: 'AssertExpectationsForObjects(t, myMock)' or 'AssertExpectationsForObjects(t, &myMock.Mock)'", obj)
continue

if m, ok := obj.(*Mock); ok {
t.Logf("Deprecated mock.AssertExpectationsForObjects(myMock.Mock) use mock.AssertExpectationsForObjects(myMock)")
obj = m
}
m := obj.(assertExpectationiser)
if !m.AssertExpectations(t) {
t.Logf("Expectations didn't match for Mock: %+v", reflect.TypeOf(m))
return false
Expand Down Expand Up @@ -712,8 +712,8 @@
return true
}

// IsMethodCallable returns true if given methodName and arguments have an
// unsatisfied expected call registered in the Mock.
// IsMethodCallable checking that the method can be called
// If the method was called more than `Repeatability` return false
func (m *Mock) IsMethodCallable(t TestingT, methodName string, arguments ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
Expand Down Expand Up @@ -833,10 +833,6 @@
// For example:
//
// args.Assert(t, IsType(""), IsType(0))
//
// Mock cannot match interface types because the contained type will be passed
// to both IsType and Mock.Called, for the zero value of all interfaces this
// will be <nil> type.
func IsType(t interface{}) *IsTypeArgument {
return &IsTypeArgument{t: reflect.TypeOf(t)}
}
Expand Down Expand Up @@ -1016,7 +1012,7 @@
actualT := reflect.TypeOf(actual)
if actualT != expected.t {
differences++
output = fmt.Sprintf("%s\t%d: FAIL: type %s != type %s - %s\n", output, i, safeTypeName(expected.t), safeTypeName(actualT), actualFmt)
output = fmt.Sprintf("%s\t%d: FAIL: type %s != type %s - %s\n", output, i, expected.t.Name(), actualT.Name(), actualFmt)
}
case *FunctionalOptionsArgument:
var name string
Expand Down Expand Up @@ -1145,15 +1141,6 @@
return s
}

// safeTypeName returns the reflect.Type's name without causing a panic.
// If the provided reflect.Type is nil, it returns the placeholder string "<nil>"
func safeTypeName(t reflect.Type) string {
if t == nil {
return "<nil>"
}
return t.Name()
}

func typeAndKind(v interface{}) (reflect.Type, reflect.Kind) {
t := reflect.TypeOf(v)
k := t.Kind()
Expand Down
26 changes: 0 additions & 26 deletions mock/mock_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mock

import (
"context"
"errors"
"fmt"
"regexp"
Expand Down Expand Up @@ -2000,25 +1999,6 @@ func Test_Arguments_Diff_WithIsTypeArgument_Failing(t *testing.T) {
assert.Contains(t, diff, `string != type int - (int=123)`)
}

func Test_Arguments_Diff_WithIsTypeArgument_InterfaceType(t *testing.T) {
t.Parallel()
var ctx = context.Background()
args := Arguments([]interface{}{IsType(ctx)})
_, count := args.Diff([]interface{}{context.Background()})
assert.Equal(t, 0, count)
}

func Test_Arguments_Diff_WithIsTypeArgument_InterfaceType_Failing(t *testing.T) {
t.Parallel()

var ctx context.Context
var args = Arguments([]interface{}{IsType(ctx)})
diff, count := args.Diff([]interface{}{context.Background()})
assert.Equal(t, 1, count)
assert.Contains(t, diff, `type <nil> != type `)

}

func Test_Arguments_Diff_WithArgMatcher(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -2461,9 +2441,3 @@ func TestIssue1785ArgumentWithMutatingStringer(t *testing.T) {
m.MethodCalled("Method", &mutatingStringer{N: 2})
m.AssertExpectations(t)
}

func TestIssue1227AssertExpectationsForObjectsWithMock(t *testing.T) {
mockT := &MockTestingT{}
AssertExpectationsForObjects(mockT, Mock{})
assert.Equal(t, 1, mockT.errorfCount)
}
Loading