|
|
package test
import ( "fmt" "github.com/gorilla/websocket" "github.com/ouxuanserver/osmanthuswine/src/helper" "github.com/panjf2000/ants" . "github.com/smartystreets/goconvey/convey" pay_service "hudongzhuanjia/services/pay" "hudongzhuanjia/utils" "hudongzhuanjia/utils/define" "math/rand" "net/http" "regexp" "runtime" "sort" "sync" "testing" "time" )
func TestHttpGet(t *testing.T) { Convey("测试http get 方法", t, func() { resp, err := Api("").Get(fmt.Sprintf("%s/%s", RootHost, "PcClient/common/WeChatOauthCtl/checkin")) So(err, ShouldBeNil) res := make(map[string]interface{}) err = resp.Json(&res) So(err, ShouldBeNil) So(res["code"], ShouldEqual, 0) }) }
func TestTime(t *testing.T) { re := regexp.MustCompile("[a-z]+:[1-9]+") fmt.Println(re.MatchString("customer:19")) }
func TestWs(t *testing.T) { ws := websocket.DefaultDialer conn, resp, err := ws.Dial("ws://127.0.0.1:20182/PcClient/Node/webSocket?activity_id=12", nil) if err != nil && resp.StatusCode == http.StatusOK { fmt.Printf("%v:%v", err, resp.StatusCode) t.Error(err) } conn.WriteJSON(map[string]interface{}{ "type": "login", "data": map[string]interface{}{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBY2NvdW50VHlwZSI6ImN1c3RvbWVyIiwiQWNjb3VudElkIjo1NCwiQ3VzdG9tZXJJZCI6NTQsIkN1c3RvbWVyUGlkIjoxOSwiVXNlcm5hbWUiOiIxNTg4OTI3Mzc3MCIsIkFjdGl2aXR5SWQiOjAsIkFyZWFJZCI6NDIsImF1ZCI6Im9zbWFudGh1c3dpbmUtYXVkaWVuY2Utb3giLCJleHAiOjE2NjA3MTY2MDMsImp0aSI6ImVlYWYyMTJjLWQ3Y2YtNGJlMy1hYWYyLWY0NDQ4ZjY2YjE5ZSIsImlzcyI6Im9zbWFudGh1c3dpbmUtaXNzdWVyLW94Iiwic3ViIjoib3NtYW50aHVzd2luZS1zdWJqZWN0LW94In0.igNC7sBFigsxRGpyjnemGm7dgEuoAyWZmMpLkDwDcto", }, }) ts, msg, err := conn.ReadMessage() if err != nil { t.Error(err) } fmt.Printf("%v:%s", ts, msg) }
func TestMd5(t *testing.T) { pw := helper.Md5("hdzj==ouxuan123") fmt.Println(pw) pw2 := helper.Md5("ouxuan123") fmt.Println(pw2) }
func TestTimeFormat(t *testing.T) { //s, _ := strconv.ParseInt("2000", 10, 64)
m := 12000 / 60 s := 12000 - m*60 h := m / 60 m = m - h*60 fmt.Printf("%02d:%02d:%02d", h, m, s) }
func TestSortSearch(t *testing.T) { fmt.Println(sort.SearchInts([]int{1, 2, 3, 3, 5, 6}, 3)) }
func TestTimeDurationGame(t *testing.T) { fmt.Println(600 - (time.Now().Unix() - 1574837339)) }
func TestInts(t *testing.T) { f := func(i *[]int64) { i = &([]int64{1, 2, 3, 4, 5}) } a := make([]int64, 0) f(&a) fmt.Println(a) }
func TestGenUrl(t *testing.T) { path, _ := utils.GenH5Qrcode(define.H5Auction, map[string]interface{}{ "activity_id": 1, "uid=": 2, "auction_id": 3, }) fmt.Println(path) }
func TestGoLoop(t *testing.T) { go func() { go func() { fmt.Println("inner") for { select { case <-time.NewTicker(1 * time.Second).C: fmt.Println("对你哎哎哎啊") } } }() fmt.Println("outer") }() time.Sleep(10 * time.Second) }
func TestAnts(t *testing.T) { runtime.GOMAXPROCS(runtime.NumCPU()) now := time.Now().Unix() wg := new(sync.WaitGroup) wg.Add(1000000) for i := 0; i < 1000000; i++ { ants.Submit(func() { defer wg.Done() fmt.Println(i) }) } wg.Wait() fmt.Println(time.Now().Unix() - now) }
func TestFor(t *testing.T) { now := time.Now().Unix() for i := 0; i < 1000000; i++ { fmt.Println(i) } fmt.Println("end===>", time.Now().Unix()-now) }
func TestChan(t *testing.T) { now := time.Now().Unix() channel := make(chan int, 0) for i := 0; i < 1000000; i++ { channel <- i } loop: for { select { case i, ok := <-channel: if ok { fmt.Println(i) } else { break loop } } } fmt.Println(time.Now().Unix() - now) }
func TestRand(t *testing.T) { r := rand.New(rand.NewSource(time.Now().UnixNano())) fmt.Println(r.Float64() * 100) }
func TestDuration(t *testing.T) { //fmt.Println(6 / 2.0)
//fmt.Println(math.Ceil(5 / 2.0))
//fmt.Println(math.Ceil(4 / 2.0))
//fmt.Println(math.Ceil(3 / 2))
//fmt.Println(2 / 2)
//fmt.Println(1 / 2)
//fmt.Println(0 / 2)
fmt.Print(time.Now().UnixNano()) }
//func TestVerifySign(t *testing.T) {
// a := wechat.GetH5PaySign(wx.Appid, "VG8BjImdNo6dHB91", "prepay_id=wx0316103340944880625537321039416000",
// "MD5", "1578039033", wx.ApiKey)
// fmt.Println(a)
//}
//func TestRedPack(t *testing.T) {
// user := new(models.User)
// exist, err := models.GetById(user, 19)
// if err != nil {
// t.Error(err)
// }
// if !exist {
// t.Errorf("error occur: %s", err)
// }
// res, err := pay_service.SendRedPack("欧轩互动", user.Openid, "测试", "123.207.246.51",
// "测试", "测试", 1, 1, 1, user.Id, 1)
// if err != nil {
// t.Error(err)
// }
// fmt.Printf("%+v", res)
//}
func TestRefundRedPack(t *testing.T) { res, err := pay_service.Refund("退款", "f8nYoKC5Gk0O5t68AzU3boo2eJfETKRf") fmt.Printf("%+v, %v", res, err) //res, err := pay_service.QueryRedPack("tDYW8edlzegSlVNaJMXsteZEeuVL")
//fmt.Printf("%+v, %+v", res, err)
}
|