Skip to content

Commit

Permalink
fix(mock): add approve build to mock (#1024)
Browse files Browse the repository at this point in the history
* fix(mock): add approve build to mock

* appease linter
  • Loading branch information
ecrupper authored Dec 11, 2023
1 parent 6fcde86 commit 140d2b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions mock/server/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,23 @@ func cancelBuild(c *gin.Context) {
c.JSON(http.StatusOK, BuildResp)
}

// approveBuild has a param :build and returns mock JSON for a http POST.
//
// Pass "0" to :build to test receiving a http 403 response.
func approveBuild(c *gin.Context) {
b := c.Param("build")

if strings.EqualFold(b, "0") {
msg := "user does not have admin permissions for the repo"

c.AbortWithStatusJSON(http.StatusForbidden, types.Error{Message: &msg})

return
}

c.JSON(http.StatusOK, fmt.Sprintf("Successfully approved build %s", b))
}

// buildQueue has a param :after returns mock JSON for a http GET.
//
// Pass "0" to :after to test receiving a http 200 response with no builds.
Expand Down
1 change: 1 addition & 0 deletions mock/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func FakeHandler() http.Handler {
e.GET("/api/v1/repos/:org/:repo/builds/:build", getBuild)
e.POST("/api/v1/repos/:org/:repo/builds/:build", restartBuild)
e.DELETE("/api/v1/repos/:org/:repo/builds/:build/cancel", cancelBuild)
e.POST("/api/v1/repos/:org/:repo/builds/:build/approve", approveBuild)
e.GET("/api/v1/repos/:org/:repo/builds/:build/logs", getLogs)
e.GET("/api/v1/repos/:org/:repo/builds", getBuilds)
e.POST("/api/v1/repos/:org/:repo/builds", addBuild)
Expand Down

0 comments on commit 140d2b1

Please sign in to comment.