api_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package elec
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. gock "gopkg.in/h2non/gock.v1"
  7. )
  8. func TestElecArcShow(t *testing.T) {
  9. convey.Convey("ArcShow", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. mid = int64(2089809)
  13. aid = int64(10110826)
  14. ip = "127.0.0.1"
  15. err error
  16. show bool
  17. )
  18. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  19. defer gock.OffAll()
  20. httpMock("GET", d.showURI).Reply(200).JSON(`{"code":20004,"data":""}`)
  21. show, err = d.ArcShow(c, mid, aid, ip)
  22. ctx.Convey("Then err should be nil.show should not be nil.", func(ctx convey.C) {
  23. ctx.So(err, convey.ShouldNotBeNil)
  24. ctx.So(show, convey.ShouldNotBeNil)
  25. })
  26. })
  27. })
  28. }
  29. func TestElecArcUpdate(t *testing.T) {
  30. convey.Convey("ArcUpdate", t, func(ctx convey.C) {
  31. var (
  32. c = context.Background()
  33. mid = int64(2089809)
  34. aid = int64(10110826)
  35. openElec = int8(1)
  36. ip = "127.0.0.1"
  37. err error
  38. )
  39. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  40. defer gock.OffAll()
  41. httpMock("GET", d.arcOpenURL).Reply(200).JSON(`{"code":20004,"data":""}`)
  42. err = d.ArcUpdate(c, mid, aid, openElec, ip)
  43. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  44. ctx.So(err, convey.ShouldNotBeNil)
  45. })
  46. })
  47. })
  48. }