gitlab_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package gitlab
  2. import (
  3. "flag"
  4. "os"
  5. "testing"
  6. "time"
  7. "go-common/app/admin/ep/saga/conf"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. var (
  11. g *Gitlab
  12. )
  13. // TestMain ...
  14. func TestMain(m *testing.M) {
  15. flag.Set("conf", "../../cmd/saga-admin-test.toml")
  16. var err error
  17. if err = conf.Init(); err != nil {
  18. panic(err)
  19. }
  20. g = New(conf.Conf.Property.Gitlab.API, conf.Conf.Property.Gitlab.Token)
  21. os.Exit(m.Run())
  22. }
  23. // TestListProjects ...
  24. func TestListProjects(t *testing.T) {
  25. Convey("ListProjects", t, func() {
  26. projects, err := g.ListProjects(1)
  27. So(err, ShouldBeNil)
  28. So(len(projects), ShouldBeGreaterThan, 1)
  29. })
  30. }
  31. func TestListProjectPipelines(t *testing.T) {
  32. Convey("listProjectPipelines", t, func() {
  33. _, _, err := g.ListProjectPipelines(1, 682, "")
  34. So(err, ShouldBeNil)
  35. })
  36. }
  37. func TestGetPipeline(t *testing.T) {
  38. Convey("GetPipeline", t, func() {
  39. _, _, err := g.GetPipeline(682, 166011)
  40. So(err, ShouldBeNil)
  41. })
  42. }
  43. func TestListProjectJobs(t *testing.T) {
  44. Convey("ListJobs", t, func() {
  45. jobs, resp, err := g.ListProjectJobs(5822, 1)
  46. So(err, ShouldBeNil)
  47. So(resp, ShouldNotBeNil)
  48. So(len(jobs), ShouldBeGreaterThan, 1)
  49. })
  50. }
  51. func TestGitlab_ListProjectMergeRequests(t *testing.T) {
  52. Convey("ListProjectMergeRequest", t, func() {
  53. var (
  54. project = 682
  55. until = time.Now()
  56. since = until.AddDate(0, -1, 0)
  57. )
  58. mrs, resp, err := g.ListProjectMergeRequests(project, &since, &until, -1)
  59. So(len(mrs), ShouldBeGreaterThan, 1)
  60. So(resp, ShouldNotBeNil)
  61. So(err, ShouldBeNil)
  62. })
  63. }
  64. func TestGitlab_ListProjectBranch(t *testing.T) {
  65. Convey("ListProjectBranch", t, func() {
  66. var (
  67. project = 682
  68. page = 1
  69. )
  70. branches, resp, err := g.ListProjectBranch(project, page)
  71. So(err, ShouldBeNil)
  72. So(len(branches), ShouldBeGreaterThan, 0)
  73. So(resp, ShouldNotBeNil)
  74. })
  75. }
  76. func TestGitlab_ListProjectCommit(t *testing.T) {
  77. Convey("List Project branch commit", t, func() {
  78. var (
  79. project = 682
  80. page = 1
  81. )
  82. commits, resp, err := g.ListProjectCommit(project, page, nil, nil)
  83. So(err, ShouldBeNil)
  84. So(commits, ShouldNotBeNil)
  85. So(resp.StatusCode, ShouldEqual, 200)
  86. })
  87. }
  88. func TestGitlab_ListProjectRunners(t *testing.T) {
  89. Convey("test list project runners", t, func() {
  90. var (
  91. project = 4928
  92. page = 1
  93. )
  94. runners, resp, err := g.ListProjectRunners(project, page)
  95. So(err, ShouldBeNil)
  96. So(resp.StatusCode, ShouldEqual, 200)
  97. So(runners, ShouldNotBeNil)
  98. })
  99. }