acc_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/job/main/passport/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. "net/url"
  8. "reflect"
  9. "testing"
  10. "github.com/bouk/monkey"
  11. "github.com/smartystreets/goconvey/convey"
  12. )
  13. func TestDao_SetToken(t *testing.T) {
  14. convey.Convey("SetToken", t, func(ctx convey.C) {
  15. token := &model.Token{
  16. Mid: 88888970,
  17. Token: "foo",
  18. }
  19. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  20. err := d.SetToken(context.TODO(), token)
  21. ctx.So(err, convey.ShouldBeNil)
  22. })
  23. })
  24. }
  25. func TestDao_DelCache(t *testing.T) {
  26. convey.Convey("DelCache", t, func(ctx convey.C) {
  27. token := "foo"
  28. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  29. err := d.DelCache(context.TODO(), token)
  30. ctx.So(err, convey.ShouldBeNil)
  31. })
  32. })
  33. }
  34. func TestDao_NotifyGame(t *testing.T) {
  35. convey.Convey("NotifyGame", t, func(ctx convey.C) {
  36. var (
  37. mid = &model.AccessInfo{}
  38. action = ""
  39. )
  40. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  41. mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.gameClient), "Get", func(d *bm.Client, _ context.Context, _, _ string, _ url.Values, _ interface{}) error {
  42. return nil
  43. })
  44. defer mock.Unpatch()
  45. err := d.NotifyGame(mid, action)
  46. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  47. ctx.So(err, convey.ShouldBeNil)
  48. })
  49. mock2 := monkey.PatchInstanceMethod(reflect.TypeOf(d.gameClient), "Get", func(d *bm.Client, _ context.Context, _, _ string, _ url.Values, _ interface{}) error {
  50. return ecode.Int(500)
  51. })
  52. defer mock2.Unpatch()
  53. err = d.NotifyGame(mid, action)
  54. ctx.Convey("Then err should not be nil.", func(ctx convey.C) {
  55. ctx.So(err, convey.ShouldNotBeNil)
  56. })
  57. })
  58. })
  59. }