-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
dependenciesPull requests that update a dependency filePull requests that update a dependency filepkg-mockAny issues related to MockAny issues related to Mock
Description
Description
To drop dependency on module objx (see #1752) I propose to replace objx.Map with an internal implementation that exposes a similar (subset) API to objx.Map that is just enough for the few users of Mock.TestData.
Proposed solution
My solution with our own mock.TestData and mock.TestDataValue types that exposes the subset of objx.Map methods used in the wild.
- Merge mock: isolate objx-dependent code in their own source files #1757.
- Add types
TestDataandTestDataValue. - Replace use of
objx.Mapwithmock.TestDatain the signature ofMock.TestData().
package mock
import "reflect"
// TestData replaces [github.com/stretchr/objx.Map].
type TestData map[string]interface{}
type reflectValue = reflect.Value
// TestDataValue replaces [github.com/stretchr/objx.Value] and exposes the same methods as [reflect.Value].
type TestDataValue struct {
reflectValue
}
// Set replaces [github.com/stretchr/objx.Map.Set].
func (td TestData) Set(selector string, v interface{}) {
td[selector] = v
}
// Get replaces [github.com/stretchr/objx.Map.Get].
func (td TestData) Get(selector string) *TestDataValue {
v, ok := td[selector]
if !ok {
return nil
}
return &TestDataValue{reflectValue: reflect.ValueOf(&v).Elem()}
}
// MustInter replaces [github.com/stretchr/objx.Value.MustInter].
func (v *TestDataValue) MustInter() interface{} {
if v == nil {
return nil
}
return v.reflectValue.Interface()
}
func (m *Mock) TestData() objx.Map {
if m.testData == nil {
m.testData = make(TestData)
}
return m.testData
}Use case
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
dependenciesPull requests that update a dependency filePull requests that update a dependency filepkg-mockAny issues related to MockAny issues related to Mock