package rtask import ( "fmt" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "reflect" "testing" "github.com/agiledragon/gomonkey/v2" . "github.com/smartystreets/goconvey/convey" ) var vals []int32 //通过接口传入的参数组 var conf *cfg.GameRdtaskCondiData func TestVerify(t *testing.T) { Convey("校验处理器测试", t, func() { Convey("校验接口参数组", func() { patches := gomonkey.ApplyGlobalVar(&conf, &cfg.GameRdtaskCondiData{ Id: 101, Type: 1, Data1: 25001, }) defer patches.Reset() patches2 := gomonkey.ApplyGlobalVar(&vals, []int32{25002}) defer patches2.Reset() n, err := lenParam(conf, vals...) fmt.Println(n, err) }) }) } func TestVerify2(t *testing.T) { Convey("校验处理测试", t, func() { Convey("rtype1", func() { var r *ModelRtask // 修改 patches := gomonkey.ApplyMethod(reflect.TypeOf(r), "GetVerifyData", func(_ *ModelRtask, uid string, condiId int32) (*pb.RtaskData, error) { return &pb.RtaskData{ Data: map[int32]int32{0: 25001}, }, nil }) defer patches.Reset() // rtask := &ModelRtaskRecord{} conf := &cfg.GameRdtaskCondiData{ Id: 101, Type: 1, Data1: 25001, } err, ok := rtask.verifyFromDb("11", conf) So(err, ShouldEqual, nil) So(ok, ShouldEqual, true) //模拟接口参数传入 patches3 := gomonkey.ApplyGlobalVar(&vals, []int32{25001}) defer patches3.Reset() condiId, _ := rtask.equalParams(conf, vals...) So(condiId, ShouldEqual, 101) }) }) }