agiledragon / agiledragon/gomonkey
使用ApplyMethod替换gin.Context的方法未生效,为何?
- Ngôn ngữ chính
- Go
- Star
- 2.3k
- Fork
- 192
- Merge trung bình
- 1 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 1
Mô tả
```go
import (
"reflect"
"testing"
"github.com/agiledragon/gomonkey"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
)
func TestSeq_GIN(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
ginCtx := &gin.Context{
Params: gin.Params{
gin.Param{
Key: "ns",
Value: "aaaa",
},
},
}
patches := gomonkey.ApplyMethod(reflect.TypeOf(ginCtx), "Param", func(_ *gin.Context, _ string) string {
return "bbbb"
})
defer patches.Reset()
println("===1", ginCtx.Param("ns"))
t.Log("===2", ginCtx.Param("ns"))
}
```
go test -v 输出结果

Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Đánh giá
Issue này chưa được đánh giá.