Skip to content

mock: replace objx.Map with our own mock.TestData type to drop objx #1852 - #1870

Open
dolmen wants to merge 4 commits into
masterfrom
dolmen/mock-replace-objx.Map-1852
Open

dolmen wants to merge 4 commits into
masterfrom
dolmen/mock-replace-objx.Map-1852

Conversation

@dolmen

@dolmen dolmen commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fix use of objx.Map in the signature of mock.Mock.TestData().

Drop github.com/stretchr/objx dependency.

This implements proposal #1852.

Changes

Motivation

This allows to drop the dependency on the objx module.

Benefits:

  • one less dependency = faster compile time for users of the testify/mock package
  • reduce supply chain risks (even if objx is in the same GitHub organization, it is maintained by different person who have never met).

Related issues

Closes #1852

@dolmen dolmen added the dependencies Pull requests that update a dependency file label Apr 8, 2026
@dolmen
dolmen requested a review from ccoVeille April 8, 2026 19:47
ccoVeille
ccoVeille previously approved these changes Apr 8, 2026
@dolmen

dolmen commented May 6, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased after merge of #1823 and rebase of #1757.

@dolmen

dolmen commented May 7, 2026

Copy link
Copy Markdown
Collaborator Author

@brackendawson Following your comment on #1757, what is your stance regarding finally removing objx here?

@dolmen dolmen self-assigned this May 7, 2026
@dolmen dolmen added the pkg-mock Any issues related to Mock label May 7, 2026
@dolmen dolmen removed their assignment May 14, 2026
dolmen added 4 commits May 14, 2026 19:12
In order to ease maintenance of downstream forks of Testify that would
remove dependency on github.com/stretchr/objx we move all uses of that
module in isolated source files. A fork without that dependency could
just remove those files.
See #1752 (comment)

The use of objx is quite contained: it is only used in Mock.TestData().
Note that we can't just remove that method or change the return value because
that would be a breaking change.
Add build tag testify_no_objx to allow to exclude method Mock.TestData()
for avoiding dependency on github.com/stretchr/objx.
Drop the last reference to dependency github.com/stretchr/objx.

Reference to objx.Map is removed (BREAKING CHANGE) from the
Mock.TestData method signature. A similar object is returned instead of
objx.Map, but we do not aim to implement the full objx.Value API:
instead we expose the reflect.Value API that should help enough the few
users of Mock.TestData to move away from objx.Map reliance.

Implemented as planned in #1852.
@dolmen
dolmen force-pushed the dolmen/mock-replace-objx.Map-1852 branch from 89f7ac6 to d6431e8 Compare May 14, 2026 17:37

@brackendawson brackendawson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change requires a major version bump. No ifs, no buts.

Comment thread mock/mock.go
// 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change:

package kata_test

import (
	"testing"

	"github.com/stretchr/objx"
	"github.com/stretchr/testify/mock"
)

func TestIfy(t *testing.T) {
	m := &mock.Mock{}
	var td objx.Map
	td = m.TestData()
	td.Set("selector", "value")
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a breaking change, as mentionned both in the commit message and in the description of this PR, and this has been discussed here: #1852 (comment). There is no other way forward to drop the objx dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking Change dependencies Pull requests that update a dependency file pkg-mock Any issues related to Mock

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mock: replace objx.Map with our own mock.TestData type to drop objx

3 participants