Skip to content

Commit

Permalink
Change Runner info lookup error
Browse files Browse the repository at this point in the history
- Standardize against existing pattern
  • Loading branch information
Birdrock authored and julian-hj committed Jun 27, 2023
1 parent cb13ea1 commit fd95efa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion api/handlers/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handlers

import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -70,7 +71,13 @@ func (h *Deployment) create(r *http.Request) (*routing.Response, error) {

runnerInfo, err := h.runnerInfoRepo.GetRunnerInfo(r.Context(), authInfo, h.runnerName)
if err != nil {
return nil, apierrors.LogAndReturn(logger, err, "Error getting runner info in repository")
var notFoundErr apierrors.NotFoundError
if errors.As(err, &notFoundErr) {
logger.Info("Could not find RunnerInfo", "runner", h.runnerName, "error", err)
ret := fmt.Errorf("The configured runner '%s' does not support rolling deploys", h.runnerName)
return nil, apierrors.NewRollingDeployNotSupportedError(ret)
}
return nil, apierrors.LogAndReturn(logger, apierrors.ForbiddenAsNotFound(err), "Error getting runner info in repository")
}

if !runnerInfo.Capabilities.RollingDeploy {
Expand Down
12 changes: 12 additions & 0 deletions api/handlers/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ var _ = Describe("Deployment", func() {
})
})

When("runner is not capable of rolling deploy", func() {
BeforeEach(func() {
runnerInfoRepo.GetRunnerInfoReturns(repositories.RunnerInfoRecord{},
apierrors.NewNotFoundError(errors.New("not found"), "RunnerInfo"))
})

It("returns an error if the RunnerInfo indicates unable to rolling deploy", func() {
Expect(rr).To(HaveHTTPStatus(http.StatusBadRequest))
Expect(rr).To(HaveHTTPBody("{\"errors\":[{\"detail\":\"The configured runner 'statefulset-runner' does not support rolling deploys\",\"title\":\"CF-RollingDeployNotSupported\",\"code\":42000}]}\n"))
})
})

It("returns a HTTP 201 Created response", func() {
Expect(rr).To(HaveHTTPStatus(http.StatusCreated))
Expect(rr).To(HaveHTTPHeaderWithValue("Content-Type", "application/json"))
Expand Down

0 comments on commit fd95efa

Please sign in to comment.