bilibili-backup/app/service/main/resource/dao/abtest/abtest_test.go
2019-04-22 02:59:20 +00:00

40 lines
1.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package abtest
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestAbtestAbTest(t *testing.T) {
convey.Convey("Abtest", t, func() {
var (
c = context.Background()
names = "test"
ipaddr = "0.0.0.0"
)
convey.Convey("When everything is correct", func(ctx convey.C) {
adr, err := d.AbTest(context.TODO(), "", "")
ctx.Convey("Then error should be niladr should not be nil", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(adr, convey.ShouldNotBeNil)
})
})
convey.Convey("When http request gets 404 error", func(ctx convey.C) {
httpMock("GET", d.testURL).Reply(404)
_, err := d.AbTest(c, names, ipaddr)
ctx.Convey("Then error should not be nil", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
})
})
convey.Convey("When http request gets code != 0", func(ctx convey.C) {
httpMock("GET", d.testURL).Reply(200).JSON(`{"code":-3,"message":"faild","data":{}}`)
_, err := d.AbTest(c, names, ipaddr)
ctx.Convey("Then error should not be nil", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
})
})
})
}