service_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "testing"
  7. "go-common/app/admin/main/block/conf"
  8. "go-common/app/admin/main/block/model"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. s *Service
  13. c = context.TODO()
  14. )
  15. func TestMain(m *testing.M) {
  16. defer os.Exit(0)
  17. flag.Set("conf", "../cmd/block-admin-test.toml")
  18. var err error
  19. if err = conf.Init(); err != nil {
  20. panic(err)
  21. }
  22. s = New()
  23. defer s.Close()
  24. m.Run()
  25. }
  26. func TestService(t *testing.T) {
  27. Convey("", t, func() {
  28. s.Ping(c)
  29. s.Close()
  30. })
  31. }
  32. func TestBlock(t *testing.T) {
  33. Convey("block", t, func() {
  34. var (
  35. p = &model.ParamBatchBlock{
  36. MIDs: []int64{1, 2, 3, 4},
  37. AdminID: 233,
  38. AdminName: "233",
  39. Source: 1,
  40. Area: model.BlockAreaNone,
  41. Reason: "test",
  42. Comment: "test",
  43. Action: model.BlockActionLimit,
  44. Duration: 1,
  45. Notify: false,
  46. }
  47. pm = &model.ParamBatchRemove{
  48. MIDs: []int64{1, 2, 3, 4},
  49. AdminID: 233,
  50. AdminName: "233",
  51. Comment: "test",
  52. Notify: false,
  53. }
  54. )
  55. err := s.BatchBlock(c, p)
  56. So(err, ShouldBeNil)
  57. err = s.BatchRemove(c, pm)
  58. So(err, ShouldBeNil)
  59. })
  60. }