broadcast_test.go 803 B

12345678910111213141516171819202122232425262728293031323334
  1. package dm
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "testing"
  7. model "go-common/app/job/main/activity/model/dm"
  8. "github.com/smartystreets/goconvey/convey"
  9. "gopkg.in/h2non/gock.v1"
  10. )
  11. func TestDmBroadcast(t *testing.T) {
  12. convey.Convey("Broadcast", t, func(ctx convey.C) {
  13. var (
  14. c = context.Background()
  15. ds, _ = json.Marshal("ttt")
  16. dm = &model.Broadcast{RoomID: 10344, CMD: "act", Info: ds}
  17. )
  18. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  19. defer gock.OffAll()
  20. url := fmt.Sprintf("%s?cids=%d", d.broadcastURL, 10344)
  21. httpMock("POST", url).Reply(200).SetHeaders(map[string]string{
  22. "Code": "0",
  23. })
  24. err := d.Broadcast(c, dm)
  25. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  26. ctx.So(err, convey.ShouldBeNil)
  27. })
  28. })
  29. })
  30. }