-
Notifications
You must be signed in to change notification settings - Fork 844
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
atc: behaviour: add ArchivePipeline endpoint
#5315 Driving this change with tests had some pain points. We decided to work outside-in, starting with an ATC integration test. It was difficult to move from the outer TDD loop to the inner - I was surprised by the number of seemingly-far-flung changes that were required to move from one failure to the next. These included: * adding an entry to the auditor to overcome a panic * modifying the `atc/api/present` package to link the DB entity to the API entity both of these things feel so easy to forget, and it might be nice if they could be described by a change in the same part of the codebase. Signed-off-by: Jamie Klassen <cklassen@pivotal.io> Co-authored-by: Bishoy Youssef <byoussef@pivotal.io> Co-authored-by: Aidan Oldershaw <aoldershaw@pivotal.io>
- Loading branch information
Showing
20 changed files
with
837 additions
and
2 deletions.
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
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,18 @@ | ||
package pipelineserver | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/concourse/concourse/atc/db" | ||
) | ||
|
||
func (s *Server) ArchivePipeline(pipelineDB db.Pipeline) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
s.logger.Debug("archive-pipeline") | ||
err := pipelineDB.Archive() | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
s.logger.Error("archive-pipeline", err) | ||
} | ||
}) | ||
} |
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,68 @@ | ||
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/dbfakes" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
//go:generate counterfeiter code.cloudfoundry.org/lager.Logger | ||
|
||
var _ = Describe("Archive 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) | ||
server = pipelineserver.NewServer( | ||
fakeLogger, | ||
new(dbfakes.FakeTeamFactory), | ||
new(dbfakes.FakePipelineFactory), | ||
"", | ||
) | ||
dbPipeline = new(dbfakes.FakePipeline) | ||
handler = server.ArchivePipeline(dbPipeline) | ||
recorder = httptest.NewRecorder() | ||
request = httptest.NewRequest("PUT", "http://example.com", nil) | ||
}) | ||
|
||
It("logs database errors", func() { | ||
expectedError := errors.New("db error") | ||
dbPipeline.ArchiveReturns(expectedError) | ||
|
||
handler.ServeHTTP(recorder, request) | ||
|
||
Expect(fakeLogger.ErrorCallCount()).To(Equal(1)) | ||
action, actualError, _ := fakeLogger.ErrorArgsForCall(0) | ||
Expect(action).To(Equal("archive-pipeline"), "wrong action name") | ||
Expect(actualError).To(Equal(expectedError)) | ||
}) | ||
|
||
It("write a debug log on every request", func() { | ||
handler.ServeHTTP(recorder, request) | ||
|
||
Expect(fakeLogger.DebugCallCount()).To(Equal(1)) | ||
action, _ := fakeLogger.DebugArgsForCall(0) | ||
Expect(action).To(Equal("archive-pipeline"), "wrong action name") | ||
}) | ||
|
||
It("logs no errors if everything works", func() { | ||
dbPipeline.ArchiveReturns(nil) | ||
|
||
handler.ServeHTTP(recorder, request) | ||
|
||
Expect(fakeLogger.ErrorCallCount()).To(Equal(0)) | ||
}) | ||
}) |
Oops, something went wrong.