abtest_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package abtest
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestAbtestAbTest(t *testing.T) {
  8. convey.Convey("Abtest", t, func() {
  9. var (
  10. c = context.Background()
  11. names = "test"
  12. ipaddr = "0.0.0.0"
  13. )
  14. convey.Convey("When everything is correct", func(ctx convey.C) {
  15. adr, err := d.AbTest(context.TODO(), "", "")
  16. ctx.Convey("Then error should be nil,adr should not be nil", func(ctx convey.C) {
  17. ctx.So(err, convey.ShouldBeNil)
  18. ctx.So(adr, convey.ShouldNotBeNil)
  19. })
  20. })
  21. convey.Convey("When http request gets 404 error", func(ctx convey.C) {
  22. httpMock("GET", d.testURL).Reply(404)
  23. _, err := d.AbTest(c, names, ipaddr)
  24. ctx.Convey("Then error should not be nil", func(ctx convey.C) {
  25. ctx.So(err, convey.ShouldNotBeNil)
  26. })
  27. })
  28. convey.Convey("When http request gets code != 0", func(ctx convey.C) {
  29. httpMock("GET", d.testURL).Reply(200).JSON(`{"code":-3,"message":"faild","data":{}}`)
  30. _, err := d.AbTest(c, names, ipaddr)
  31. ctx.Convey("Then error should not be nil", func(ctx convey.C) {
  32. ctx.So(err, convey.ShouldNotBeNil)
  33. })
  34. })
  35. })
  36. }