geetest_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package geetest
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "testing"
  7. "go-common/app/interface/main/account/conf"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. var (
  11. d *Dao
  12. )
  13. func TestMain(m *testing.M) {
  14. if os.Getenv("DEPLOY_ENV") != "" {
  15. flag.Set("app_id", "main.account.account-interface")
  16. flag.Set("conf_token", "967eef77ad40b478234f11b0d489d6d6")
  17. flag.Set("tree_id", "3815")
  18. flag.Set("conf_version", "docker-1")
  19. flag.Set("deploy_env", "uat")
  20. flag.Set("conf_host", "config.bilibili.co")
  21. flag.Set("conf_path", "/tmp")
  22. flag.Set("region", "sh")
  23. flag.Set("zone", "sh001")
  24. } else {
  25. flag.Set("conf", "../../cmd/account-interface-example.toml")
  26. }
  27. flag.Parse()
  28. if err := conf.Init(); err != nil {
  29. panic(err)
  30. }
  31. d = New(conf.Conf)
  32. m.Run()
  33. os.Exit(0)
  34. }
  35. func TestGeetestPreProcess(t *testing.T) {
  36. convey.Convey("PreProcess", t, func(ctx convey.C) {
  37. var (
  38. c = context.Background()
  39. mid = int64(11)
  40. geeType = ""
  41. gc = d.c.Geetest.PC
  42. newCaptcha = int(1)
  43. )
  44. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  45. challenge, err := d.PreProcess(c, mid, geeType, gc, newCaptcha)
  46. ctx.Convey("Then err should be nil.challenge should not be nil.", func(ctx convey.C) {
  47. ctx.So(err, convey.ShouldBeNil)
  48. ctx.So(challenge, convey.ShouldNotBeNil)
  49. })
  50. })
  51. })
  52. }
  53. func TestGeetestValidate(t *testing.T) {
  54. convey.Convey("Validate", t, func(ctx convey.C) {
  55. var (
  56. c = context.Background()
  57. challenge = "ac7e67bb9b8e3e567186159e63df2153cs"
  58. seccode = "7bda121544bd035032b2b5e390bce5d7"
  59. clientType = "web"
  60. captchaID = "0926f406a4a5433a45faf33ae9a721c3"
  61. mid = int64(11)
  62. )
  63. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  64. res, err := d.Validate(c, challenge, seccode, clientType, captchaID, mid)
  65. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  66. ctx.So(err, convey.ShouldBeNil)
  67. ctx.So(res, convey.ShouldNotBeNil)
  68. })
  69. })
  70. })
  71. }