service_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "path/filepath"
  7. "testing"
  8. "go-common/app/admin/main/dm/conf"
  9. "go-common/app/admin/main/dm/model/oplog"
  10. "go-common/library/log"
  11. manager "go-common/library/queue/databus/report"
  12. . "github.com/smartystreets/goconvey/convey"
  13. )
  14. var (
  15. svr *Service
  16. )
  17. func TestMain(m *testing.M) {
  18. var (
  19. err error
  20. )
  21. dir, _ := filepath.Abs("../cmd/dm-admin-test.toml")
  22. if err = flag.Set("conf", dir); err != nil {
  23. panic(err)
  24. }
  25. if err = conf.Init(); err != nil {
  26. panic(err)
  27. }
  28. // log.Init(nil)
  29. svr = New(conf.Conf)
  30. // manager log init
  31. manager.InitManager(conf.Conf.ManagerLog)
  32. os.Exit(m.Run())
  33. }
  34. func WithService(f func(s *Service)) func() {
  35. return func() {
  36. f(svr)
  37. }
  38. }
  39. func TestOpLog(t *testing.T) {
  40. var (
  41. c = context.TODO()
  42. cid int64 = 12
  43. typ int32 = 1
  44. operator int64 = 219
  45. dmids = []int64{719150137}
  46. subject = "status"
  47. originVal = "1"
  48. currentVal = "2"
  49. remark = "备注"
  50. source = oplog.SourceManager
  51. operatorType = oplog.OperatorAdmin
  52. )
  53. Convey("OpLog", t, WithService(func(s *Service) {
  54. err := svr.OpLog(c, cid, operator, typ, dmids, subject, originVal, currentVal, remark, source, operatorType)
  55. So(err, ShouldBeNil)
  56. }))
  57. }
  58. func TestQueryOpLogs(t *testing.T) {
  59. var (
  60. c = context.TODO()
  61. dmid int64 = 719150137
  62. )
  63. Convey("QueryOpLogs", t, WithService(func(s *Service) {
  64. objs, err := svr.QueryOpLogs(c, dmid)
  65. log.Info("%v", objs)
  66. So(err, ShouldBeNil)
  67. }))
  68. }