Closed hankeyyh closed 8 months ago
I use gomonkey.ApplyFunc mock a func in for loop, then call it. Why it returns the same result every time.
func Test2(t *testing.T) { for i := 0; i < 3; i++ { gomonkey.ApplyFunc(env.Loc, func() int { tmp := i + 1 return tmp }) t.Logf("%p, %v", env.Loc, env.Loc()) } } output: 0x8b85c0, 1 0x8b85c0, 1 0x8b85c0, 1
solved, not using -gcflags=l
I use gomonkey.ApplyFunc mock a func in for loop, then call it. Why it returns the same result every time.