full_test.go 880 B

123456789101112131415161718192021222324252627282930313233
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaoFullImport(t *testing.T) {
  8. var (
  9. c = context.Background()
  10. build = int(0)
  11. )
  12. convey.Convey("FullImport", t, func(ctx convey.C) {
  13. ctx.Convey("Http code err", func(ctx convey.C) {
  14. httpMock("GET", d.fullURL).Reply(-400).JSON(``)
  15. _, err := d.FullImport(c, build)
  16. ctx.So(err, convey.ShouldNotBeNil)
  17. })
  18. ctx.Convey("Business code err", func(ctx convey.C) {
  19. httpMock("GET", d.fullURL).Reply(200).JSON(`{"code":-400}`)
  20. _, err := d.FullImport(c, build)
  21. ctx.So(err, convey.ShouldNotBeNil)
  22. })
  23. ctx.Convey("Everything goes well", func(ctx convey.C) {
  24. httpMock("GET", d.fullURL).Reply(200).JSON(`{"code":0,"data":[{"id":1}]}`)
  25. data, err := d.FullImport(c, build)
  26. ctx.So(err, convey.ShouldBeNil)
  27. ctx.So(data, convey.ShouldNotBeNil)
  28. })
  29. })
  30. }