upgrade_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package goblin
  2. import (
  3. "context"
  4. "go-common/app/interface/main/tv/model"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestGoblinVerUpdate(t *testing.T) {
  9. var (
  10. ctx = context.Background()
  11. ver = &model.VerUpdate{}
  12. )
  13. convey.Convey("VerUpdate", t, func(c convey.C) {
  14. c.Convey("Then err should be nil.result,errCode should not be nil.", func(c convey.C) {
  15. result, errCode, err := d.VerUpdate(ctx, ver)
  16. httpMock("GET", d.conf.Host.ReqURL).Reply(200).JSON(`{
  17. "Data": {"ver":123},
  18. "message": "succ",
  19. "code": 0
  20. }`)
  21. c.So(err, convey.ShouldBeNil)
  22. c.So(errCode, convey.ShouldBeNil)
  23. c.So(result, convey.ShouldNotBeNil)
  24. })
  25. c.Convey("http error", func(c convey.C) {
  26. _, _, err := d.VerUpdate(ctx, ver)
  27. httpMock("GET", d.conf.Host.ReqURL).Reply(404).JSON(``)
  28. c.So(err, convey.ShouldNotBeNil)
  29. })
  30. c.Convey("code error", func(c convey.C) {
  31. _, _, err := d.VerUpdate(ctx, ver)
  32. httpMock("GET", d.conf.Host.ReqURL).Reply(200).JSON(`{"code":400}`)
  33. c.So(err, convey.ShouldNotBeNil)
  34. })
  35. })
  36. }