push_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package bnj
  2. import (
  3. "context"
  4. "testing"
  5. "gopkg.in/h2non/gock.v1"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestBnjPushAll(t *testing.T) {
  9. convey.Convey("PushAll", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. msg = `{"second":100,"name":"啊*"}`
  13. )
  14. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  15. err := d.PushAll(c, msg)
  16. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  17. ctx.So(err, convey.ShouldBeNil)
  18. })
  19. })
  20. })
  21. }
  22. func TestBnjSendMessage(t *testing.T) {
  23. convey.Convey("SendMessage", t, func(ctx convey.C) {
  24. var (
  25. c = context.Background()
  26. mids = []int64{2089809}
  27. mc = "1_21_1"
  28. title = "【bilibili2019拜年祭档案揭秘】001"
  29. msg = "飞雪连天射白鹿,笑书神侠倚碧鸳。当V家碰到金庸,会碰撞出怎样的火花?来拜年祭后台看看吧~"
  30. )
  31. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  32. defer gock.OffAll()
  33. httpMock("POST", d.messageURL).Reply(200).JSON(`{"code":0}`)
  34. err := d.SendMessage(c, mids, mc, title, msg)
  35. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  36. ctx.So(err, convey.ShouldBeNil)
  37. })
  38. })
  39. })
  40. }