bigdata_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaoRegionArcs(t *testing.T) {
  8. convey.Convey("RegionArcs", t, func() {
  9. var (
  10. c = context.Background()
  11. rid = int32(1)
  12. remoteIP = "0.0.0.0"
  13. )
  14. convey.Convey("When http request gets 404 error", func(ctx convey.C) {
  15. httpMock("GET", d.regionURI).MatchParam("rid", "0").Reply(502).JSON(`{"code":-500}`)
  16. _, _, err := d.RegionArcs(c, rid, remoteIP)
  17. ctx.Convey("Then error should not be nil", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldNotBeNil)
  19. })
  20. })
  21. convey.Convey("When http request gets code == 0", func(ctx convey.C) {
  22. httpMock("GET", d.regionURI).MatchParam("rid", "1").Reply(200).JSON(`{"code":0,"message":"ok","data":{"avid":[28868622,29365735,29621166],"count":4602378}}`)
  23. aids, total, err := d.RegionArcs(c, rid, remoteIP)
  24. ctx.Convey("Then error should not be nil", func(ctx convey.C) {
  25. ctx.So(err, convey.ShouldBeNil)
  26. ctx.So(total, convey.ShouldBeGreaterThan, 0)
  27. ctx.So(len(aids), convey.ShouldBeGreaterThan, 0)
  28. })
  29. })
  30. })
  31. }
  32. func TestDaoRegionTagArcs(t *testing.T) {
  33. convey.Convey("RegionTagArcs", t, func() {
  34. var (
  35. c = context.Background()
  36. rid = int32(136)
  37. tagID = int64(4577)
  38. remoteIP = "0.0.0.0"
  39. params = map[string]string{"rid": "136", "tag_id": "4577"}
  40. )
  41. convey.Convey("When http request gets code == 0", func(ctx convey.C) {
  42. httpMock("GET", d.regionTagURI).MatchParams(params).Reply(200).JSON(`{"code":0,"message":"ok","data":{"avid":[28868622,29365735,29621166],"count":4602378}}`)
  43. aids, err := d.RegionTagArcs(c, rid, tagID, remoteIP)
  44. ctx.Convey("Then error should not be nil", func(ctx convey.C) {
  45. ctx.So(err, convey.ShouldBeNil)
  46. ctx.So(len(aids), convey.ShouldBeGreaterThan, 0)
  47. })
  48. })
  49. })
  50. }