From 140d2b1492b726db24c60f3c469abaaabbe6f97d Mon Sep 17 00:00:00 2001 From: Easton Crupper <65553218+ecrupper@users.noreply.github.com> Date: Mon, 11 Dec 2023 15:54:34 -0500 Subject: [PATCH] fix(mock): add approve build to mock (#1024) * fix(mock): add approve build to mock * appease linter --- mock/server/build.go | 17 +++++++++++++++++ mock/server/server.go | 1 + 2 files changed, 18 insertions(+) diff --git a/mock/server/build.go b/mock/server/build.go index 3edc55bf0..9bd02a07e 100644 --- a/mock/server/build.go +++ b/mock/server/build.go @@ -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. diff --git a/mock/server/server.go b/mock/server/server.go index 699062868..0b7dcff79 100644 --- a/mock/server/server.go +++ b/mock/server/server.go @@ -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)