Skip to content
Open
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
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- run: ./.ci.readme.fmt.sh
- run: ./.ci.govet.sh
- run: go test -v -race ./...
- run: go test -tags testify_no_objx ./...
test:
runs-on: ubuntu-latest
strategy:
Expand All @@ -39,3 +40,4 @@ jobs:
with:
go-version: ${{ matrix.go_version }}
- run: go test -v -race ./...
- run: go test -tags testify_no_objx ./...
13 changes: 1 addition & 12 deletions mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

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

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -311,7 +310,7 @@ type Mock struct {

// TestData holds any data that might be useful for testing. Testify ignores
// this data completely allowing you to do whatever you like with it.
testData objx.Map
testData testData

mutex sync.Mutex
}
Expand All @@ -324,16 +323,6 @@ func (m *Mock) String() string {
return fmt.Sprintf("%[1]T<%[1]p>", m)
}

// TestData holds any data that might be useful for testing. Testify ignores
// this data completely allowing you to do whatever you like with it.
func (m *Mock) TestData() objx.Map {
if m.testData == nil {
m.testData = make(objx.Map)
}

return m.testData
}

/*
Setting expectations
*/
Expand Down
5 changes: 5 additions & 0 deletions mock/mock_no_objx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build testify_no_objx || testify_no_deps

package mock

type testData = struct{}
21 changes: 21 additions & 0 deletions mock/mock_objx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This source file isolates the uses of the objx module to ease
// maintenance of downstream forks that remove that dependency.
// See https://github.com/stretchr/testify/issues/1752

//go:build !testify_no_objx && !testify_no_deps

package mock

import "github.com/stretchr/objx"

type testData = objx.Map

// TestData holds any data that might be useful for testing. Testify ignores
// this data completely allowing you to do whatever you like with it.
func (m *Mock) TestData() objx.Map {
if m.testData == nil {
m.testData = make(objx.Map)
}

return m.testData
}
21 changes: 21 additions & 0 deletions mock/mock_objx_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build !testify_no_objx && !testify_no_deps

package mock

import (
"testing"

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

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

var mockedService = new(TestExampleImplementation)

if assert.NotNil(t, mockedService.TestData()) {

mockedService.TestData().Set("something", 123)
assert.Equal(t, 123, mockedService.TestData().Get("something").Data())
}
}
12 changes: 0 additions & 12 deletions mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,6 @@ func (m *MockTestingT) FailNow() {
Mock
*/

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

var mockedService = new(TestExampleImplementation)

if assert.NotNil(t, mockedService.TestData()) {

mockedService.TestData().Set("something", 123)
assert.Equal(t, 123, mockedService.TestData().Get("something").Data())
}
}

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

Expand Down