Closed ericuni closed 1 year ago
You can mock generic function by gomonkey, for example:
func Add[T int | float32 | float64](a T, b T) T {
return a + b
}
var AddInt = Add[int]
func TestGenericPatch(t *testing.T) {
Convey("TestGenericPatch", t, func() {
So(AddInt(1, 2), ShouldEqual, 3)
patches := ApplyFuncVarReturn(&AddInt, 5)
defer patches.Reset()
So(AddInt(1, 2), ShouldEqual, 5)
})
}
Running tool: /usr/local/go/bin/go test -timeout 30s -run ^TestGenericPatch$ goconvey-study/slice -v -count=1 -gcflags=all=-l
=== RUN TestGenericPatch
TestGenericPatch ✔✔
2 total assertions
--- PASS: TestGenericPatch (0.00s)
PASS
ok goconvey-study/slice 0.007s
Does gomonkey support generics for now?