wechat_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/interface/main/web/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. "gopkg.in/h2non/gock.v1"
  8. )
  9. func TestDaoWxHot(t *testing.T) {
  10. convey.Convey("WxHot", t, func(ctx convey.C) {
  11. var (
  12. c = context.Background()
  13. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. defer gock.OffAll()
  16. httpMock("GET", d.wxHotURL).Reply(200).JSON(`{"code":0,"list":[{"aid":111,"score":10},{"aid":2222,"score":20}]}`)
  17. aids, err := d.WxHot(c)
  18. ctx.Convey("Then err should be nil.aids should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. ctx.So(aids, convey.ShouldNotBeNil)
  21. })
  22. })
  23. })
  24. }
  25. func TestDaoSetWxHotCache(t *testing.T) {
  26. convey.Convey("SetWxHotCache", t, func(ctx convey.C) {
  27. var (
  28. c = context.Background()
  29. arcs = []*model.WxArchive{{Aid: 1111}, {Aid: 2222}}
  30. )
  31. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  32. err := d.SetWxHotCache(c, arcs)
  33. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  34. ctx.So(err, convey.ShouldBeNil)
  35. })
  36. })
  37. })
  38. }
  39. func TestDaoWxHotCache(t *testing.T) {
  40. convey.Convey("WxHotCache", t, func(ctx convey.C) {
  41. var (
  42. c = context.Background()
  43. )
  44. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  45. arcs, err := d.WxHotCache(c)
  46. ctx.Convey("Then err should be nil.arcs should not be nil.", func(ctx convey.C) {
  47. ctx.So(err, convey.ShouldBeNil)
  48. ctx.Printf("%+v", arcs)
  49. })
  50. })
  51. })
  52. }
  53. func TestDaoWxHotBakCache(t *testing.T) {
  54. convey.Convey("WxHotBakCache", t, func(ctx convey.C) {
  55. var (
  56. c = context.Background()
  57. )
  58. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  59. arcs, err := d.WxHotBakCache(c)
  60. ctx.Convey("Then err should be nil.arcs should not be nil.", func(ctx convey.C) {
  61. ctx.So(err, convey.ShouldBeNil)
  62. ctx.Printf("%+v", arcs)
  63. })
  64. })
  65. })
  66. }