log_test.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "testing"
  7. "github.com/smartystreets/goconvey/convey"
  8. "go-common/app/admin/main/aegis/model"
  9. "go-common/app/admin/main/aegis/model/common"
  10. "go-common/app/admin/main/aegis/model/net"
  11. "go-common/app/admin/main/aegis/model/resource"
  12. "go-common/app/admin/main/aegis/model/task"
  13. )
  14. func Test_AuditLog(t *testing.T) {
  15. opt := &model.SubmitOptions{
  16. Binds: []int64{1, 2},
  17. EngineOption: model.EngineOption{
  18. BaseOptions: common.BaseOptions{
  19. RID: 1,
  20. },
  21. Result: &resource.Result{},
  22. },
  23. }
  24. res := &net.TriggerResult{
  25. SubmitToken: &net.TokenPackage{
  26. Values: map[string]interface{}{
  27. "state": 1,
  28. "forbid": 2,
  29. },
  30. TokenIDList: []int64{3, 4},
  31. },
  32. ResultToken: &net.TokenPackage{
  33. Values: map[string]interface{}{
  34. "state": 1,
  35. "forbid": 2,
  36. },
  37. TokenIDList: []int64{3, 4},
  38. },
  39. }
  40. err := s.sendAuditLog(context.TODO(), "submit", opt, res, model.LogTypeAuditSubmit)
  41. fmt.Printf("err(%v)\n", err)
  42. t.Fail()
  43. }
  44. func Test_TaskLog(t *testing.T) {
  45. Content := map[string]interface{}{
  46. "task": &task.Task{},
  47. }
  48. bs, _ := json.Marshal(Content)
  49. fmt.Printf("bs(%s)", string(bs))
  50. t.Fail()
  51. }
  52. func Test_ResourceLog(t *testing.T) {
  53. Content := map[string]interface{}{
  54. "opt": &model.AddOption{},
  55. "res": &net.TriggerResult{
  56. SubmitToken: &net.TokenPackage{
  57. Values: map[string]interface{}{
  58. "state": 1,
  59. "forbid": 2,
  60. },
  61. TokenIDList: []int64{3, 4},
  62. },
  63. ResultToken: &net.TokenPackage{
  64. Values: map[string]interface{}{
  65. "state": 1,
  66. "forbid": 2,
  67. },
  68. TokenIDList: []int64{3, 4},
  69. },
  70. },
  71. "oids": []int64{1, 2, 3},
  72. "err": "dqfgug",
  73. }
  74. bs, _ := json.Marshal(Content)
  75. fmt.Printf("bs(%s)", string(bs))
  76. t.Fail()
  77. }
  78. func TestService_SearchAuditLog1(t *testing.T) {
  79. convey.Convey("SearchAuditLog", t, func(ctx convey.C) {
  80. pm := &model.SearchAuditLogParam{
  81. OID: []string{"196962673299031503"},
  82. BusinessID: 1,
  83. Ps: 20,
  84. Pn: 1,
  85. Username: []string{"业务方"},
  86. CtimeFrom: "2018-11-01 00:00:00",
  87. CtimeTo: "",
  88. TaskID: []int64{0, 660},
  89. State: "0",
  90. }
  91. data, pager, err := s.SearchAuditLog(cntx, pm)
  92. t.Logf("pager(%+v)", pager)
  93. for i, item := range data {
  94. t.Logf("data i=%d, %+v", i, item)
  95. }
  96. ctx.So(err, convey.ShouldBeNil)
  97. })
  98. }
  99. func TestService_SearchAuditLogCSV(t *testing.T) {
  100. convey.Convey("SearchAuditLogCSV", t, func(ctx convey.C) {
  101. pm := &model.SearchAuditLogParam{
  102. OID: []string{"196962673299031503"},
  103. BusinessID: 1,
  104. Ps: 20,
  105. Pn: 1,
  106. //Username: "chenxuefeng",
  107. CtimeFrom: "2018-11-01 00:00:00",
  108. CtimeTo: "",
  109. //TaskID: []int64{0, 55},
  110. //State: "1",
  111. }
  112. data, err := s.SearchAuditLogCSV(cntx, pm)
  113. for i, item := range data {
  114. t.Logf("data i=%d, %+v", i, item)
  115. }
  116. ctx.So(err, convey.ShouldBeNil)
  117. })
  118. }
  119. func TestService_TrackResource(t *testing.T) {
  120. convey.Convey("TrackResource", t, func(ctx convey.C) {
  121. pm := &model.TrackParam{
  122. OID: "186464454672655532112",
  123. BusinessID: 1,
  124. Pn: 2,
  125. Ps: 2,
  126. LastPageTime: "2018-12-06 14:01:15",
  127. }
  128. data, p, err := s.TrackResource(cntx, pm)
  129. ctx.So(err, convey.ShouldBeNil)
  130. t.Logf("data(%+v) pager(%+v), params(%+v)", data, p, pm)
  131. for i, item := range data.Add {
  132. t.Logf("data.add i=%d, %+v", i, item)
  133. }
  134. for i, item := range data.Audit {
  135. t.Logf("data.audit i=%d, %+v", i, item)
  136. }
  137. })
  138. }
  139. func TestService_searchConsumerLog(t *testing.T) {
  140. convey.Convey("searchConsumerLog", t, func(ctx convey.C) {
  141. res, err := s.searchConsumerLog(cntx, 1, 1, []string{"on"}, []int64{1148}, 10)
  142. ctx.So(err, convey.ShouldBeNil)
  143. ctx.So(res, convey.ShouldNotBeNil)
  144. t.Logf("res(%+v)", res)
  145. })
  146. }