message_test.go 686 B

12345678910111213141516171819202122232425262728293031323334
  1. package dao
  2. import (
  3. "context"
  4. "strings"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. "gopkg.in/h2non/gock.v1"
  8. )
  9. func httpMock(method, url string) *gock.Request {
  10. r := gock.New(url)
  11. r.Method = strings.ToUpper(method)
  12. return r
  13. }
  14. func TestDaoSendMessage(t *testing.T) {
  15. var (
  16. c = context.Background()
  17. mid = int64(123)
  18. title = "test"
  19. msg = "test"
  20. mc = "test"
  21. )
  22. convey.Convey("SendMessage", t, func(ctx convey.C) {
  23. d.client.SetTransport(gock.DefaultTransport)
  24. defer gock.OffAll()
  25. httpMock("POST", notifyURL).Reply(200).JSON(`{"code":0,"message":"0"}`)
  26. err := d.SendMessage(c, mid, title, msg, mc)
  27. ctx.So(err, convey.ShouldBeNil)
  28. })
  29. }