card_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "testing"
  6. "time"
  7. "go-common/app/admin/main/card/conf"
  8. "go-common/app/admin/main/card/model"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. c = context.TODO()
  13. s *Service
  14. )
  15. func init() {
  16. var (
  17. err error
  18. )
  19. flag.Set("conf", "../cmd/test.toml")
  20. if err = conf.Init(); err != nil {
  21. panic(err)
  22. }
  23. c = context.Background()
  24. if s == nil {
  25. s = New(conf.Conf)
  26. }
  27. time.Sleep(time.Second)
  28. }
  29. // go test -test.v -test.run TestCardsByGid
  30. func TestCardsByGid(t *testing.T) {
  31. Convey("TestCardsByGid ", t, func() {
  32. card, err := s.CardsByGid(c, 2)
  33. t.Logf("v(%v)", card)
  34. So(err, ShouldBeNil)
  35. })
  36. }
  37. func TestUpdateCardState(t *testing.T) {
  38. Convey("TestUpdateCardState ", t, func() {
  39. err := s.UpdateCardState(c, &model.ArgState{ID: 1, State: 1})
  40. So(err, ShouldBeNil)
  41. })
  42. }
  43. func TestDeleteCard(t *testing.T) {
  44. Convey("TestDeleteCard ", t, func() {
  45. err := s.DeleteCard(c, 1)
  46. So(err, ShouldBeNil)
  47. })
  48. }
  49. func TestUpdateGroupState(t *testing.T) {
  50. Convey("TestUpdateGroupState ", t, func() {
  51. err := s.UpdateGroupState(c, &model.ArgState{ID: 2, State: 1})
  52. So(err, ShouldBeNil)
  53. })
  54. }
  55. func TestDeleteGroup(t *testing.T) {
  56. Convey("TestDeleteGroup ", t, func() {
  57. err := s.DeleteGroup(c, 2)
  58. So(err, ShouldBeNil)
  59. })
  60. }
  61. // go test -test.v -test.run TestGroupList
  62. func TestGroupList(t *testing.T) {
  63. Convey("TestGroupList ", t, func() {
  64. card, err := s.GroupList(c, &model.ArgQueryGroup{GroupID: 2})
  65. t.Logf("v(%v)", card)
  66. So(err, ShouldBeNil)
  67. })
  68. }
  69. func TestCardOrderChange(t *testing.T) {
  70. Convey("TestCardOrderChange ", t, func() {
  71. err := s.CardOrderChange(c, &model.ArgIds{Ids: []int64{2, 3}})
  72. So(err, ShouldBeNil)
  73. })
  74. }
  75. func TestGroupOrderChange(t *testing.T) {
  76. Convey("TestGroupOrderChange ", t, func() {
  77. err := s.GroupOrderChange(c, &model.ArgIds{Ids: []int64{1}})
  78. So(err, ShouldBeNil)
  79. })
  80. }
  81. func TestAddGroup(t *testing.T) {
  82. Convey("TestAddGroup ", t, func() {
  83. err := s.AddGroup(c, &model.AddGroup{Name: "test17", State: 0})
  84. So(err, ShouldBeNil)
  85. })
  86. }