mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-02 04:32:23 +00:00
Add some testsvfor bitbucket forge (#2097)
This commit is contained in:
parent
957cb95484
commit
b0fe17322f
2 changed files with 84 additions and 1 deletions
|
@ -178,6 +178,36 @@ func Test_bitbucket(t *testing.T) {
|
|||
})
|
||||
})
|
||||
|
||||
g.Describe("When requesting repo branch HEAD", func() {
|
||||
g.It("Should return the details", func() {
|
||||
branchHead, err := c.BranchHead(ctx, fakeUser, fakeRepo, "branch_name")
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(branchHead).Equal("branch_head_name")
|
||||
})
|
||||
g.It("Should handle not found errors", func() {
|
||||
_, err := c.BranchHead(ctx, fakeUser, fakeRepo, "branch_not_found")
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("When requesting repo pull requests", func() {
|
||||
listOpts := model.ListOptions{
|
||||
All: false,
|
||||
Page: 1,
|
||||
PerPage: 10,
|
||||
}
|
||||
g.It("Should return the details", func() {
|
||||
repoPRs, err := c.PullRequests(ctx, fakeUser, fakeRepo, &listOpts)
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repoPRs[0].Title).Equal("PRs title")
|
||||
g.Assert(repoPRs[0].Index).Equal(int64(123))
|
||||
})
|
||||
g.It("Should handle not found errors", func() {
|
||||
_, err := c.PullRequests(ctx, fakeUser, fakeRepoNotFound, &listOpts)
|
||||
g.Assert(err).IsNotNil()
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("When requesting repo directory contents", func() {
|
||||
g.It("Should return the details", func() {
|
||||
files, err := c.Dir(ctx, fakeUser, fakeRepo, fakePipeline, "/dir")
|
||||
|
|
|
@ -38,7 +38,8 @@ func Handler() http.Handler {
|
|||
e.GET("/2.0/repositories/:owner", getUserRepos)
|
||||
e.GET("/2.0/user/", getUser)
|
||||
e.GET("/2.0/user/permissions/repositories", getPermissions)
|
||||
|
||||
e.GET("/2.0/repositories/:owner/:name/commits/:commit", getBranchHead)
|
||||
e.GET("/2.0/repositories/:owner/:name/pullrequests", getPullRequests)
|
||||
return e
|
||||
}
|
||||
|
||||
|
@ -119,6 +120,24 @@ func getRepoFile(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func getBranchHead(c *gin.Context) {
|
||||
switch c.Param("commit") {
|
||||
case "branch_name":
|
||||
c.String(200, branchCommitsPayload)
|
||||
default:
|
||||
c.String(404, "")
|
||||
}
|
||||
}
|
||||
|
||||
func getPullRequests(c *gin.Context) {
|
||||
switch c.Param("name") {
|
||||
case "repo_name":
|
||||
c.String(200, pullRequestsPayload)
|
||||
default:
|
||||
c.String(404, "")
|
||||
}
|
||||
}
|
||||
|
||||
func createRepoStatus(c *gin.Context) {
|
||||
switch c.Param("name") {
|
||||
case "repo_not_found":
|
||||
|
@ -248,6 +267,40 @@ const repoDirPayload = `
|
|||
}
|
||||
`
|
||||
|
||||
const branchCommitsPayload = `
|
||||
{
|
||||
"values": [
|
||||
{
|
||||
"hash": "branch_head_name"
|
||||
},
|
||||
{
|
||||
"hash": "random1"
|
||||
},
|
||||
{
|
||||
"hash": "random2"
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
|
||||
const pullRequestsPayload = `
|
||||
{
|
||||
"values": [
|
||||
{
|
||||
"id": 123,
|
||||
"title": "PRs title"
|
||||
},
|
||||
{
|
||||
"id": 456,
|
||||
"title": "Another PRs title"
|
||||
}
|
||||
],
|
||||
"pagelen": 10,
|
||||
"size": 2,
|
||||
"page": 1
|
||||
}
|
||||
`
|
||||
|
||||
const userPayload = `
|
||||
{
|
||||
"username": "superman",
|
||||
|
|
Loading…
Reference in a new issue