Add some testsvfor bitbucket forge (#2097)

This commit is contained in:
Michalis Zampetakis 2023-08-03 03:06:03 +03:00 committed by GitHub
parent 957cb95484
commit b0fe17322f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 84 additions and 1 deletions

View file

@ -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.Describe("When requesting repo directory contents", func() {
g.It("Should return the details", func() { g.It("Should return the details", func() {
files, err := c.Dir(ctx, fakeUser, fakeRepo, fakePipeline, "/dir") files, err := c.Dir(ctx, fakeUser, fakeRepo, fakePipeline, "/dir")

View file

@ -38,7 +38,8 @@ func Handler() http.Handler {
e.GET("/2.0/repositories/:owner", getUserRepos) e.GET("/2.0/repositories/:owner", getUserRepos)
e.GET("/2.0/user/", getUser) e.GET("/2.0/user/", getUser)
e.GET("/2.0/user/permissions/repositories", getPermissions) 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 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) { func createRepoStatus(c *gin.Context) {
switch c.Param("name") { switch c.Param("name") {
case "repo_not_found": 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 = ` const userPayload = `
{ {
"username": "superman", "username": "superman",