-
Notifications
You must be signed in to change notification settings - Fork 846
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
atc: behaviour: unpausing archived pipelines fails
#5316 Rather than adding a concrete error type to check against, we elected to create an interface for our domain-specific error to satisfy - see: https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully Following the example of trigger-job we decided that 409 Conflict was the most logical http status to use to represent this kind of policy violation. We decided to add the `Conflict` interface to the `db` package because it seems there is no more-appropriate "business logic" or "policy" layer to place this kind of validation error. Since multiple backend members in the web node interact with pipelines directly via the database, it seems justified to place the business logic as close to that integration boundary as possible. Recent painful experiences with observability motivated the choice to treat logging more like a feature, and have unit tests that specifically require it. Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io> Co-authored-by: Jamie Klassen <cklassen@pivotal.io>
- Loading branch information
1 parent
b404fbf
commit 711e3c7
Showing
8 changed files
with
322 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package pipelineserver_test | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
"net/http/httptest" | ||
|
||
"github.com/concourse/concourse/atc/api/pipelineserver" | ||
"github.com/concourse/concourse/atc/api/pipelineserver/pipelineserverfakes" | ||
"github.com/concourse/concourse/atc/db" | ||
"github.com/concourse/concourse/atc/db/dbfakes" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Unpause Handler", func() { | ||
var ( | ||
fakeLogger *pipelineserverfakes.FakeLogger | ||
server *pipelineserver.Server | ||
dbPipeline *dbfakes.FakePipeline | ||
handler http.Handler | ||
recorder *httptest.ResponseRecorder | ||
request *http.Request | ||
) | ||
|
||
BeforeEach(func() { | ||
fakeLogger = new(pipelineserverfakes.FakeLogger) | ||
fakeLogger.SessionReturns(fakeLogger) | ||
server = pipelineserver.NewServer( | ||
fakeLogger, | ||
new(dbfakes.FakeTeamFactory), | ||
new(dbfakes.FakePipelineFactory), | ||
"", | ||
) | ||
dbPipeline = new(dbfakes.FakePipeline) | ||
handler = server.UnpausePipeline(dbPipeline) | ||
recorder = httptest.NewRecorder() | ||
request = httptest.NewRequest("PUT", "http://example.com", nil) | ||
}) | ||
|
||
Context("when there is a conflict error", func() { | ||
var expectedError db.Conflict | ||
|
||
BeforeEach(func() { | ||
expectedError = new(dbfakes.FakeConflict) | ||
dbPipeline.UnpauseReturns(expectedError) | ||
}) | ||
|
||
It("logs the error", func() { | ||
handler.ServeHTTP(recorder, request) | ||
|
||
Expect(fakeLogger.ErrorCallCount()).To(Equal(1)) | ||
action, actualError, _ := fakeLogger.ErrorArgsForCall(0) | ||
Expect(action).To(Equal("failed-to-unpause-pipeline"), "wrong action name") | ||
Expect(actualError).To(Equal(expectedError)) | ||
}) | ||
|
||
It("returns a 409 status code", func() { | ||
handler.ServeHTTP(recorder, request) | ||
|
||
Expect(recorder.Code).To(Equal(http.StatusConflict)) | ||
}) | ||
}) | ||
|
||
Context("when there is a database error", func() { | ||
var expectedError error | ||
|
||
BeforeEach(func() { | ||
expectedError = errors.New("db error") | ||
dbPipeline.UnpauseReturns(expectedError) | ||
}) | ||
|
||
It("logs the error", func() { | ||
handler.ServeHTTP(recorder, request) | ||
|
||
Expect(fakeLogger.ErrorCallCount()).To(Equal(1)) | ||
action, actualError, _ := fakeLogger.ErrorArgsForCall(0) | ||
Expect(action).To(Equal("failed-to-unpause-pipeline"), "wrong action name") | ||
Expect(actualError).To(Equal(expectedError)) | ||
}) | ||
|
||
It("returns a 500 status code", func() { | ||
handler.ServeHTTP(recorder, request) | ||
|
||
Expect(recorder.Code).To(Equal(http.StatusInternalServerError)) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package db | ||
|
||
import "fmt" | ||
|
||
//go:generate counterfeiter . Conflict | ||
|
||
type Conflict interface { | ||
error | ||
Conflict() string | ||
} | ||
|
||
type conflict string | ||
|
||
func (c conflict) Error() string { | ||
return fmt.Sprintf("conflict error: %s", string(c)) | ||
} | ||
|
||
func (c conflict) Conflict() string { | ||
return string(c) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters