互动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
4.8 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package test
  2. import (
  3. "fmt"
  4. "github.com/gorilla/websocket"
  5. "github.com/ouxuanserver/osmanthuswine/src/helper"
  6. "github.com/panjf2000/ants"
  7. . "github.com/smartystreets/goconvey/convey"
  8. pay_service "hudongzhuanjia/services/pay"
  9. "hudongzhuanjia/utils"
  10. "hudongzhuanjia/utils/define"
  11. "math/rand"
  12. "net/http"
  13. "regexp"
  14. "runtime"
  15. "sort"
  16. "sync"
  17. "testing"
  18. "time"
  19. )
  20. func TestHttpGet(t *testing.T) {
  21. Convey("测试http get 方法", t, func() {
  22. resp, err := Api("").Get(fmt.Sprintf("%s/%s", RootHost, "PcClient/common/WeChatOauthCtl/checkin"))
  23. So(err, ShouldBeNil)
  24. res := make(map[string]interface{})
  25. err = resp.Json(&res)
  26. So(err, ShouldBeNil)
  27. So(res["code"], ShouldEqual, 0)
  28. })
  29. }
  30. func TestTime(t *testing.T) {
  31. re := regexp.MustCompile("[a-z]+:[1-9]+")
  32. fmt.Println(re.MatchString("customer:19"))
  33. }
  34. func TestWs(t *testing.T) {
  35. ws := websocket.DefaultDialer
  36. conn, resp, err := ws.Dial("ws://127.0.0.1:20182/PcClient/Node/webSocket?activity_id=12", nil)
  37. if err != nil && resp.StatusCode == http.StatusOK {
  38. fmt.Printf("%v:%v", err, resp.StatusCode)
  39. t.Error(err)
  40. }
  41. conn.WriteJSON(map[string]interface{}{
  42. "type": "login",
  43. "data": map[string]interface{}{
  44. "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBY2NvdW50VHlwZSI6ImN1c3RvbWVyIiwiQWNjb3VudElkIjo1NCwiQ3VzdG9tZXJJZCI6NTQsIkN1c3RvbWVyUGlkIjoxOSwiVXNlcm5hbWUiOiIxNTg4OTI3Mzc3MCIsIkFjdGl2aXR5SWQiOjAsIkFyZWFJZCI6NDIsImF1ZCI6Im9zbWFudGh1c3dpbmUtYXVkaWVuY2Utb3giLCJleHAiOjE2NjA3MTY2MDMsImp0aSI6ImVlYWYyMTJjLWQ3Y2YtNGJlMy1hYWYyLWY0NDQ4ZjY2YjE5ZSIsImlzcyI6Im9zbWFudGh1c3dpbmUtaXNzdWVyLW94Iiwic3ViIjoib3NtYW50aHVzd2luZS1zdWJqZWN0LW94In0.igNC7sBFigsxRGpyjnemGm7dgEuoAyWZmMpLkDwDcto",
  45. },
  46. })
  47. ts, msg, err := conn.ReadMessage()
  48. if err != nil {
  49. t.Error(err)
  50. }
  51. fmt.Printf("%v:%s", ts, msg)
  52. }
  53. func TestMd5(t *testing.T) {
  54. pw := helper.Md5("hdzj==ouxuan123")
  55. fmt.Println(pw)
  56. pw2 := helper.Md5("ouxuan123")
  57. fmt.Println(pw2)
  58. }
  59. func TestTimeFormat(t *testing.T) {
  60. //s, _ := strconv.ParseInt("2000", 10, 64)
  61. m := 12000 / 60
  62. s := 12000 - m*60
  63. h := m / 60
  64. m = m - h*60
  65. fmt.Printf("%02d:%02d:%02d", h, m, s)
  66. }
  67. func TestSortSearch(t *testing.T) {
  68. fmt.Println(sort.SearchInts([]int{1, 2, 3, 3, 5, 6}, 3))
  69. }
  70. func TestTimeDurationGame(t *testing.T) {
  71. fmt.Println(600 - (time.Now().Unix() - 1574837339))
  72. }
  73. func TestInts(t *testing.T) {
  74. f := func(i *[]int64) {
  75. i = &([]int64{1, 2, 3, 4, 5})
  76. }
  77. a := make([]int64, 0)
  78. f(&a)
  79. fmt.Println(a)
  80. }
  81. func TestGenUrl(t *testing.T) {
  82. path, _ := utils.GenH5Qrcode(define.H5Auction, map[string]interface{}{
  83. "activity_id": 1,
  84. "uid=": 2,
  85. "auction_id": 3,
  86. })
  87. fmt.Println(path)
  88. }
  89. func TestGoLoop(t *testing.T) {
  90. go func() {
  91. go func() {
  92. fmt.Println("inner")
  93. for {
  94. select {
  95. case <-time.NewTicker(1 * time.Second).C:
  96. fmt.Println("对你哎哎哎啊")
  97. }
  98. }
  99. }()
  100. fmt.Println("outer")
  101. }()
  102. time.Sleep(10 * time.Second)
  103. }
  104. func TestAnts(t *testing.T) {
  105. runtime.GOMAXPROCS(runtime.NumCPU())
  106. now := time.Now().Unix()
  107. wg := new(sync.WaitGroup)
  108. wg.Add(1000000)
  109. for i := 0; i < 1000000; i++ {
  110. ants.Submit(func() {
  111. defer wg.Done()
  112. fmt.Println(i)
  113. })
  114. }
  115. wg.Wait()
  116. fmt.Println(time.Now().Unix() - now)
  117. }
  118. func TestFor(t *testing.T) {
  119. now := time.Now().Unix()
  120. for i := 0; i < 1000000; i++ {
  121. fmt.Println(i)
  122. }
  123. fmt.Println("end===>", time.Now().Unix()-now)
  124. }
  125. func TestChan(t *testing.T) {
  126. now := time.Now().Unix()
  127. channel := make(chan int, 0)
  128. for i := 0; i < 1000000; i++ {
  129. channel <- i
  130. }
  131. loop:
  132. for {
  133. select {
  134. case i, ok := <-channel:
  135. if ok {
  136. fmt.Println(i)
  137. } else {
  138. break loop
  139. }
  140. }
  141. }
  142. fmt.Println(time.Now().Unix() - now)
  143. }
  144. func TestRand(t *testing.T) {
  145. r := rand.New(rand.NewSource(time.Now().UnixNano()))
  146. fmt.Println(r.Float64() * 100)
  147. }
  148. func TestDuration(t *testing.T) {
  149. //fmt.Println(6 / 2.0)
  150. //fmt.Println(math.Ceil(5 / 2.0))
  151. //fmt.Println(math.Ceil(4 / 2.0))
  152. //fmt.Println(math.Ceil(3 / 2))
  153. //fmt.Println(2 / 2)
  154. //fmt.Println(1 / 2)
  155. //fmt.Println(0 / 2)
  156. fmt.Print(time.Now().UnixNano())
  157. }
  158. //func TestVerifySign(t *testing.T) {
  159. // a := wechat.GetH5PaySign(wx.Appid, "VG8BjImdNo6dHB91", "prepay_id=wx0316103340944880625537321039416000",
  160. // "MD5", "1578039033", wx.ApiKey)
  161. // fmt.Println(a)
  162. //}
  163. //func TestRedPack(t *testing.T) {
  164. // user := new(models.User)
  165. // exist, err := models.GetById(user, 19)
  166. // if err != nil {
  167. // t.Error(err)
  168. // }
  169. // if !exist {
  170. // t.Errorf("error occur: %s", err)
  171. // }
  172. // res, err := pay_service.SendRedPack("欧轩互动", user.Openid, "测试", "123.207.246.51",
  173. // "测试", "测试", 1, 1, 1, user.Id, 1)
  174. // if err != nil {
  175. // t.Error(err)
  176. // }
  177. // fmt.Printf("%+v", res)
  178. //}
  179. func TestRefundRedPack(t *testing.T) {
  180. res, err := pay_service.Refund("退款", "9dAV4ROBNLZgAHzrRmF55uCKsGvNGkeE")
  181. fmt.Printf("%+v, %v", res, err)
  182. //res, err := pay_service.QueryRedPack("tDYW8edlzegSlVNaJMXsteZEeuVL")
  183. //fmt.Printf("%+v, %+v", res, err)
  184. }