db_project_test.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. package dao
  2. import (
  3. "testing"
  4. "go-common/app/admin/ep/saga/model"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestProjectExist(t *testing.T) {
  8. convey.Convey("ProjectExist", t, func(ctx convey.C) {
  9. var (
  10. projectID = int(682)
  11. projectID2 = int(6820)
  12. )
  13. ctx.Convey("When projectID exist", func(ctx convey.C) {
  14. b, err := d.ProjectExist(projectID)
  15. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  16. ctx.So(err, convey.ShouldBeNil)
  17. ctx.So(b, convey.ShouldEqual, true)
  18. })
  19. })
  20. ctx.Convey("When projectID not exist", func(ctx convey.C) {
  21. bb, err := d.ProjectExist(projectID2)
  22. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  23. ctx.So(err, convey.ShouldBeNil)
  24. ctx.So(bb, convey.ShouldEqual, false)
  25. })
  26. })
  27. })
  28. }
  29. func TestFavorite(t *testing.T) {
  30. convey.Convey("Favorite project", t, func(ctx convey.C) {
  31. var (
  32. userName = "zhangsan"
  33. projectID = 333
  34. )
  35. ctx.Convey("add favorite project", func(ctx convey.C) {
  36. err := d.AddFavorite(userName, projectID)
  37. ctx.Convey("The err should be nil.", func(ctx convey.C) {
  38. ctx.So(err, convey.ShouldBeNil)
  39. })
  40. })
  41. ctx.Convey("get favorite project", func(ctx convey.C) {
  42. favorites, err := d.FavoriteProjects(userName)
  43. ctx.Convey("The err should be nil.", func(ctx convey.C) {
  44. ctx.So(err, convey.ShouldBeNil)
  45. ctx.So(len(favorites), convey.ShouldEqual, 1)
  46. ctx.So(favorites[0].UserName, convey.ShouldEqual, "zhangsan")
  47. ctx.So(favorites[0].ProjID, convey.ShouldEqual, 333)
  48. })
  49. })
  50. ctx.Convey("delete favorite project", func(ctx convey.C) {
  51. err := d.DelFavorite(userName, projectID)
  52. ctx.Convey("delete err should be nil.", func(ctx convey.C) {
  53. ctx.So(err, convey.ShouldBeNil)
  54. })
  55. favorites, err := d.FavoriteProjects(userName)
  56. ctx.Convey("get err should be nil.", func(ctx convey.C) {
  57. ctx.So(err, convey.ShouldBeNil)
  58. ctx.So(len(favorites), convey.ShouldEqual, 0)
  59. })
  60. })
  61. })
  62. }
  63. func TestProjectInfoByID(t *testing.T) {
  64. convey.Convey("ProjectInfoByID", t, func(ctx convey.C) {
  65. ctx.Convey("add project info", func(ctx convey.C) {
  66. addInfo := &model.ProjectInfo{
  67. ProjectID: 11111,
  68. Name: "myProject",
  69. Description: "myProject des",
  70. WebURL: "git@git.bilibili.test/test.git",
  71. Repo: "git@git.bilibili.test/test.git",
  72. DefaultBranch: "master",
  73. Saga: true,
  74. Runner: false,
  75. }
  76. err := d.AddProjectInfo(addInfo)
  77. ctx.Convey("Add Project Info. Then err should be nil. ", func(ctx convey.C) {
  78. ctx.So(err, convey.ShouldBeNil)
  79. })
  80. info, err := d.ProjectInfoByID(11111)
  81. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  82. ctx.So(err, convey.ShouldBeNil)
  83. ctx.So(info.Name, convey.ShouldEqual, "myProject")
  84. ctx.So(info.Repo, convey.ShouldEqual, "git@git.bilibili.test/test.git")
  85. ctx.So(info.Saga, convey.ShouldEqual, true)
  86. })
  87. })
  88. ctx.Convey("update project info", func(ctx convey.C) {
  89. updateInfo := &model.ProjectInfo{
  90. ProjectID: 11111,
  91. Name: "lisi",
  92. Description: "lisi des",
  93. WebURL: "git@git.bilibili.test/test.git",
  94. Repo: "git@git.bilibili.test/test.git",
  95. DefaultBranch: "dev",
  96. Saga: true,
  97. Runner: false,
  98. }
  99. err := d.UpdateProjectInfo(11111, updateInfo)
  100. ctx.Convey("update Project Info. Then err should be nil. ", func(ctx convey.C) {
  101. ctx.So(err, convey.ShouldBeNil)
  102. })
  103. info, err := d.ProjectInfoByID(11111)
  104. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  105. ctx.So(err, convey.ShouldBeNil)
  106. ctx.So(info.Name, convey.ShouldEqual, "lisi")
  107. ctx.So(info.Description, convey.ShouldEqual, "lisi des")
  108. ctx.So(info.DefaultBranch, convey.ShouldEqual, "dev")
  109. })
  110. })
  111. ctx.Convey("query not exist project info", func(ctx convey.C) {
  112. _, err := d.ProjectInfoByID(6820)
  113. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  114. ctx.So(err, convey.ShouldNotBeNil)
  115. })
  116. })
  117. })
  118. }
  119. func TestDaoHasProjectInfo(t *testing.T) {
  120. convey.Convey("HasProjectInfo", t, func(ctx convey.C) {
  121. var (
  122. projectID = int(682)
  123. projectID2 = int(6820)
  124. )
  125. ctx.Convey("When projectID exist", func(ctx convey.C) {
  126. b, err := d.HasProjectInfo(projectID)
  127. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  128. ctx.So(err, convey.ShouldBeNil)
  129. ctx.So(b, convey.ShouldEqual, true)
  130. })
  131. })
  132. ctx.Convey("When projectID not exist", func(ctx convey.C) {
  133. b, err := d.HasProjectInfo(projectID2)
  134. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  135. ctx.So(err, convey.ShouldBeNil)
  136. ctx.So(b, convey.ShouldEqual, false)
  137. })
  138. })
  139. })
  140. }
  141. func TestQueryProjectInfo(t *testing.T) {
  142. convey.Convey("QueryProjectInfo", t, func(ctx convey.C) {
  143. var (
  144. projectName = "andruid"
  145. projectUrl = "git@git-test.bilibili.co:android/andruid.git"
  146. projectInfoRequest = &model.ProjectInfoRequest{
  147. Name: projectName,
  148. }
  149. )
  150. ctx.Convey("query project exist", func(ctx convey.C) {
  151. var url string
  152. total, projectInfo, err := d.QueryProjectInfo(false, projectInfoRequest)
  153. for _, project := range projectInfo {
  154. url = project.Repo
  155. }
  156. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  157. ctx.So(err, convey.ShouldBeNil)
  158. ctx.So(total, convey.ShouldEqual, 1)
  159. ctx.So(url, convey.ShouldEqual, projectUrl)
  160. })
  161. })
  162. })
  163. }
  164. func TestQueryConfigInfo(t *testing.T) {
  165. convey.Convey("QueryConfigInfo", t, func(ctx convey.C) {
  166. var (
  167. projectName = "Kratos"
  168. projectName2 = "android-blue"
  169. queryObject = "saga"
  170. )
  171. ctx.Convey("query saga config exist", func(ctx convey.C) {
  172. total, err := d.QueryConfigInfo(projectName, "", "", queryObject)
  173. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  174. ctx.So(err, convey.ShouldBeNil)
  175. ctx.So(total, convey.ShouldEqual, 1)
  176. })
  177. })
  178. ctx.Convey("query saga config not exist", func(ctx convey.C) {
  179. total, err := d.QueryConfigInfo(projectName2, "", "", queryObject)
  180. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  181. ctx.So(err, convey.ShouldBeNil)
  182. ctx.So(total, convey.ShouldEqual, 0)
  183. })
  184. })
  185. })
  186. }