ut_test.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package service
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/admin/main/apm/model/ut"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestServiceUtDetailList(t *testing.T) {
  9. convey.Convey("UtDetailList", t, func(ctx convey.C) {
  10. req := &ut.DetailReq{
  11. CommitID: "4f5ca7122e023c605555ed4bddf274709635d019",
  12. PKG: "go-common/app/admin/main/apm",
  13. }
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. utpkgs, err := svr.UtDetailList(context.Background(), req)
  16. ctx.Convey("Than utpkgs should not be nil. err should be nil", func(ctx convey.C) {
  17. ctx.So(err, convey.ShouldBeNil)
  18. ctx.So(utpkgs, convey.ShouldNotBeNil)
  19. })
  20. })
  21. })
  22. }
  23. func TestServiceUtHistoryCommit(t *testing.T) {
  24. convey.Convey("UtHistoryCommit", t, func(ctx convey.C) {
  25. dt := &ut.HistoryCommitReq{
  26. MergeID: 1,
  27. Ps: 20,
  28. Pn: 1,
  29. }
  30. ctx.Convey("When everything goes possitive", func(ctx convey.C) {
  31. utcmts, count, err := svr.UtHistoryCommit(context.Background(), dt)
  32. ctx.Convey("Then err should be nil.count shoulde be greater than 0.utcmts should not be nil", func(ctx convey.C) {
  33. ctx.So(err, convey.ShouldBeNil)
  34. ctx.So(count, convey.ShouldBeGreaterThan, 0)
  35. ctx.So(utcmts, convey.ShouldNotBeNil)
  36. t.Logf("history count: %+v", count)
  37. for _, commit := range utcmts {
  38. for _, pkg := range commit.PkgAnls {
  39. t.Logf("%s %s cov:%.2f\n", pkg.CommitID, pkg.PKG, pkg.Coverage)
  40. }
  41. }
  42. })
  43. })
  44. })
  45. }
  46. //
  47. //func TestService_CreateUtMerge(t *testing.T) {
  48. // convey.Convey("CreateUtMerge", t, func() {
  49. // res := &ut.UploadRes{
  50. // CommitID: "eaefwa",
  51. // UserName: "ChengXing",
  52. // MergeID: 1000,
  53. // }
  54. // err := svr.AddUTMerge(context.Background(), res)
  55. // convey.So(err, convey.ShouldBeNil)
  56. // })
  57. //}
  58. //
  59. //func TestService_CreateUtCommit(t *testing.T) {
  60. // convey.Convey("CreateUtCommit", t, func() {
  61. // res := &ut.UploadRes{
  62. // CommitID: "eaefwa",
  63. // UserName: "ChengXing",
  64. // MergeID: 1000,
  65. // }
  66. // err := svr.AddUTCommit(context.Background(), res)
  67. // convey.So(err, convey.ShouldBeNil)
  68. // })
  69. //}
  70. //
  71. //func TestService_CreateUtPKG(t *testing.T) {
  72. // convey.Convey("CreateUtPKG", t, func() {
  73. // pkg := &ut.PkgAnls{
  74. // CommitID: "eawfsdfeasdfe",
  75. // PassRate: 64.12,
  76. // PKG: "go-common/app/server/main/coin/dao",
  77. // Assertions: 10,
  78. // Passed: 8,
  79. // }
  80. // res := &ut.UploadRes{
  81. // CommitID: "eaefwa",
  82. // UserName: "ChengXing",
  83. // MergeID: 1000,
  84. // }
  85. // err := svr.AddUTPKG(context.Background(), pkg, res, "", "")
  86. // convey.So(err, convey.ShouldBeNil)
  87. // })
  88. //}
  89. // func TestService_SAGAReport(t *testing.T) {
  90. // convey.Convey("SAGAReport", t, func() {
  91. // saga, err := svr.SAGAReport(context.Background(), "8c9d27c106caf6325c1155d127fcc952d1f4a441")
  92. // convey.So(saga, convey.ShouldNotBeEmpty)
  93. // convey.So(err, convey.ShouldBeNil)
  94. // for _, s := range saga {
  95. // t.Logf("Coverage:(%.02f) PKG:(%s)", s.Coverage, s.PKG)
  96. // }
  97. // })
  98. // }
  99. func TestServiceQATrend(t *testing.T) {
  100. convey.Convey("QATrend", t, func(ctx convey.C) {
  101. req := &ut.QATrendReq{
  102. User: "fengshanshan",
  103. LastTime: 30,
  104. Period: "hour",
  105. StartTime: 1540465325,
  106. EndTime: 1540551725,
  107. }
  108. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  109. trend, err := svr.QATrend(context.Background(), req)
  110. t.Logf("trend:%+v\n", trend)
  111. ctx.Convey("Than trend should not be nil. err should be nil", func(ctx convey.C) {
  112. ctx.So(err, convey.ShouldBeNil)
  113. ctx.So(trend, convey.ShouldNotBeNil)
  114. })
  115. })
  116. })
  117. }
  118. func TestServiceUTGernalCommit(t *testing.T) {
  119. convey.Convey("UTGernalCommit", t, func(ctx convey.C) {
  120. req := "ae1377033a11ca85a19bca365af32a5b0ebea31c,324a7609f2be27ccbedf7540f970982317d6cd6b,a1e94b169c728dab26ff583f2619b35d40519752"
  121. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  122. commits, err := svr.UTGernalCommit(context.Background(), req)
  123. for _, commit := range commits {
  124. t.Logf("commit:%+v\n", commit)
  125. t.Logf("commit:%+v\n", commit.GitlabCommit)
  126. }
  127. ctx.Convey("Than commitInfo should not be nil. err should be nil", func(ctx convey.C) {
  128. ctx.So(err, convey.ShouldBeNil)
  129. ctx.So(commits, convey.ShouldNotBeNil)
  130. })
  131. })
  132. })
  133. }
  134. func TestService_CommitHistory(t *testing.T) {
  135. convey.Convey("CommitHistory", t, func() {
  136. data, err := svr.CommitHistory(context.Background(), "zhaobingqing", 10)
  137. convey.So(data, convey.ShouldNotBeEmpty)
  138. convey.So(err, convey.ShouldBeNil)
  139. for _, d := range data {
  140. t.Logf("d.MergeID=%d, d.CommitID=%s, d.PKG=%s, d.Coverage=%0.2f, d.PassRate=%0.2f", d.MergeID, d.CommitID, d.PKG, d.Coverage, d.PassRate)
  141. }
  142. })
  143. }