qcloud_test.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/service/main/spy/model"
  6. "net/url"
  7. "testing"
  8. "time"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. func TestDaohmacsha1(t *testing.T) {
  12. convey.Convey("hmacsha1", t, func(ctx convey.C) {
  13. var (
  14. key = ""
  15. text = ""
  16. )
  17. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  18. h := d.hmacsha1(key, text)
  19. ctx.Convey("Then h should not be nil.", func(ctx convey.C) {
  20. ctx.So(h, convey.ShouldNotBeNil)
  21. })
  22. })
  23. })
  24. }
  25. func TestDaomakeURL(t *testing.T) {
  26. convey.Convey("makeURL", t, func(ctx convey.C) {
  27. var (
  28. method = "1"
  29. action = "1"
  30. region = "1"
  31. secretID = "1"
  32. secretKey = "1"
  33. charset = "1"
  34. URL = "1"
  35. )
  36. args := url.Values{}
  37. args.Set("accountType", fmt.Sprintf("%d", model.AccountType))
  38. args.Set("uid", fmt.Sprintf("%d", 1))
  39. args.Set("phoneNumber", "13262609601")
  40. args.Set("registerTime", fmt.Sprintf("%d", time.Now().Unix()))
  41. args.Set("registerIp", "127.0.0.1")
  42. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  43. req := d.makeURL(method, action, region, secretID, secretKey, args, charset, URL)
  44. ctx.Convey("Then req should not be nil.", func(ctx convey.C) {
  45. ctx.So(req, convey.ShouldNotBeNil)
  46. })
  47. })
  48. })
  49. }
  50. func TestDaomakeQueryString(t *testing.T) {
  51. convey.Convey("makeQueryString", t, func(ctx convey.C) {
  52. var (
  53. v url.Values
  54. )
  55. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  56. str := d.makeQueryString(v)
  57. ctx.Convey("Then str should not be nil.", func(ctx convey.C) {
  58. ctx.So(str, convey.ShouldNotBeNil)
  59. })
  60. })
  61. })
  62. }
  63. func TestDaoRegisterProtection(t *testing.T) {
  64. convey.Convey("RegisterProtection", t, func(ctx convey.C) {
  65. var (
  66. c = context.Background()
  67. ip = "127.0.0.1"
  68. )
  69. args := url.Values{}
  70. args.Set("accountType", fmt.Sprintf("%d", model.AccountType))
  71. args.Set("uid", fmt.Sprintf("%d", 1))
  72. args.Set("phoneNumber", "13262609601")
  73. args.Set("registerTime", fmt.Sprintf("%d", time.Now().Unix()))
  74. args.Set("registerIp", ip)
  75. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  76. level, err := d.RegisterProtection(c, args, ip)
  77. ctx.Convey("Then err should be nil.level should not be nil.", func(ctx convey.C) {
  78. ctx.So(err, convey.ShouldBeNil)
  79. ctx.So(level, convey.ShouldNotBeNil)
  80. })
  81. })
  82. })
  83. }