Skip to content

Commit

Permalink
test: rendering playbook params
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Sep 23, 2024
1 parent 72f8382 commit 1706720
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
8 changes: 6 additions & 2 deletions playbook/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func HandlePlaybookRun(c echo.Context) error {
})
}

type GetParamsResponse struct {
Params []v1.PlaybookParameter `json:"params"`
}

func HandleGetPlaybookParams(c echo.Context) error {
ctx := c.Request().Context().(context.Context)

Expand Down Expand Up @@ -136,8 +140,8 @@ func HandleGetPlaybookParams(c echo.Context) error {
return ctx.Oops().Wrapf(err, "failed to walk template")
}

return c.JSON(http.StatusOK, map[string]any{
"params": spec.Parameters,
return c.JSON(http.StatusOK, GetParamsResponse{
Params: spec.Parameters,
})
}

Expand Down
23 changes: 23 additions & 0 deletions playbook/playbook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,29 @@ var _ = Describe("Playbook", func() {
}
})

It("should render params", func() {
requestyBody := map[string]any{
"id": configPlaybook.ID.String(),
"config_id": dummy.EKSCluster.ID.String(),
}

response, err := http.NewClient().
Auth(dummy.JohnDoe.Email, "").
R(DefaultContext).
Header("Content-Type", "application/json").
Post(fmt.Sprintf("%s/playbook/%s/params", server.URL, configPlaybook.ID), requestyBody)
Expect(err).To(BeNil())

var body GetParamsResponse
err = json.NewDecoder(response.Body).Decode(&body)
Expect(err).To(BeNil())

Expect(len(body.Params)).To(Equal(2))
Expect(body.Params[0].Name).To(Equal("path"))
Expect(body.Params[1].Name).To(Equal("name"))
Expect(string(body.Params[1].Default)).To(Equal(*dummy.EKSCluster.Name))
})

It("should store playbook run via API", func() {
run := sdk.RunParams{
ID: configPlaybook.ID,
Expand Down

0 comments on commit 1706720

Please sign in to comment.