abtest_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "math/rand"
  7. "testing"
  8. "go-common/app/service/openplatform/abtest/conf"
  9. "go-common/library/cache/redis"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. var testID int
  13. func init() {
  14. flag.Parse()
  15. if err := conf.Init(); err != nil {
  16. panic(fmt.Errorf("conf.Init() error(%v)", err))
  17. }
  18. d = New(conf.Conf)
  19. }
  20. func TestActByGroup(t *testing.T) {
  21. Convey("TestActByGroup: ", t, func() {
  22. _, err := d.ActByGroup(context.TODO(), 1)
  23. So(err, ShouldBeNil)
  24. })
  25. }
  26. func TestListAb(t *testing.T) {
  27. Convey("TestListAb: ", t, func() {
  28. _, _, err := d.ListAb(context.TODO(), 1, 2, "0,1,2")
  29. So(err, ShouldBeNil)
  30. })
  31. }
  32. var testCase = "testxx"
  33. func TestAddAb(t *testing.T) {
  34. Convey("TestAddAb: ", t, func() {
  35. var err error
  36. testID, err = redis.Int(d.AddAb(context.TODO(), "test", "test", `{"precision":100,"ratio":[80,20]}`, rand.Intn(10000000), 0, 1, "test"))
  37. So(err, ShouldBeNil)
  38. So(testID, ShouldNotEqual, 0)
  39. })
  40. }
  41. func TestUpAb(t *testing.T) {
  42. Convey("TestUpAb: ", t, func() {
  43. res, err := d.UpAb(context.TODO(), testID, "test", testCase, `{"precision":100,"ratio":[80,20]}`, 0, "update", 1, 0, 1)
  44. So(err, ShouldBeNil)
  45. So(res, ShouldEqual, 1)
  46. })
  47. }
  48. func TestAb(t *testing.T) {
  49. Convey("TestAb: ", t, func() {
  50. res, err := d.Ab(context.TODO(), testID)
  51. So(err, ShouldBeNil)
  52. So(res.Desc, ShouldEqual, testCase)
  53. })
  54. }
  55. func TestUpStatus(t *testing.T) {
  56. Convey("TestUpSta: ", t, func() {
  57. res, err := d.UpStatus(context.TODO(), testID, 1, "test", 1)
  58. So(err, ShouldBeNil)
  59. So(res, ShouldEqual, 1)
  60. })
  61. Convey("TestUpSta: ", t, func() {
  62. res, err := d.UpStatus(context.TODO(), testID, 0, "test", 1)
  63. So(err, ShouldBeNil)
  64. So(res, ShouldEqual, 1)
  65. })
  66. }
  67. func TestDelStatus(t *testing.T) {
  68. Convey("TestDelSta: ", t, func() {
  69. res, err := d.DelAb(context.TODO(), testID)
  70. So(err, ShouldBeNil)
  71. So(res, ShouldEqual, 1)
  72. })
  73. }