group_test.go 1000 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/service/openplatform/abtest/model"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. var g = model.Group{
  9. Name: "test",
  10. Desc: "test add",
  11. }
  12. var testDesc = "test update"
  13. func TestAddGroup(t *testing.T) {
  14. Convey("TestAddGroup: ", t, func() {
  15. var err error
  16. testID, err = d.AddGroup(context.TODO(), g)
  17. So(err, ShouldBeNil)
  18. })
  19. }
  20. func TestUpdateGroup(t *testing.T) {
  21. g.Desc = testDesc
  22. g.ID = testID
  23. Convey("TestUpdateGroup: ", t, func() {
  24. res, err := d.UpdateGroup(context.TODO(), g)
  25. So(err, ShouldBeNil)
  26. So(res, ShouldEqual, 1)
  27. })
  28. }
  29. func TestListGroup(t *testing.T) {
  30. Convey("TestListGroup: ", t, func() {
  31. res, err := d.ListGroup(context.TODO())
  32. So(err, ShouldBeNil)
  33. x := res[len(res)-1]
  34. So(x.Name, ShouldEqual, g.Name)
  35. })
  36. }
  37. func TestDeleteGroup(t *testing.T) {
  38. Convey("TestDeleteGroup: ", t, func() {
  39. res, err := d.DeleteGroup(context.TODO(), testID)
  40. So(err, ShouldBeNil)
  41. So(res, ShouldEqual, 1)
  42. })
  43. }