コード例 #1
0
ファイル: handlers.go プロジェクト: cloudfoundry/cc-uploader
func New(uploader ccclient.Uploader, poller ccclient.Poller, logger lager.Logger) (http.Handler, error) {
	return rata.NewRouter(ccuploader.Routes, rata.Handlers{
		ccuploader.UploadDropletRoute:        upload_droplet.New(uploader, poller, logger),
		ccuploader.UploadBuildArtifactsRoute: upload_build_artifacts.New(uploader, logger),
	})
}
コード例 #2
0
var _ = Describe("UploadBuildArtifacts", func() {
	Describe("ServeHTTP", func() {
		var incomingRequest *http.Request
		var responseWriter http.ResponseWriter
		var outgoingResponse *httptest.ResponseRecorder
		var uploader fake_ccclient.FakeUploader
		var logger lager.Logger

		BeforeEach(func() {
			outgoingResponse = httptest.NewRecorder()
			responseWriter = outgoingResponse
		})

		JustBeforeEach(func() {
			logger = lager.NewLogger("fake-logger")
			buildArtifactsUploadHandler := upload_build_artifacts.New(&uploader, logger)

			buildArtifactsUploadHandler.ServeHTTP(responseWriter, incomingRequest)
		})

		Context("When the request does not include a build artifacts upload URI", func() {
			BeforeEach(func() {
				var err error
				incomingRequest, err = http.NewRequest("POST", "http://example.com", bytes.NewBufferString(""))
				Expect(err).NotTo(HaveOccurred())

				uploader = fake_ccclient.FakeUploader{}
			})

			It("responds with an error code", func() {
				Expect(outgoingResponse.Code).To(Equal(http.StatusBadRequest))