Beispiel #1
0
func initializeServer(logger lager.Logger, uploaderConfig config.UploaderConfig) ifrit.Runner {
	transport := &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		Dial: (&net.Dialer{
			Timeout:   ccUploadDialTimeout,
			KeepAlive: ccUploadKeepAlive,
		}).Dial,
		TLSClientConfig: &tls.Config{
			InsecureSkipVerify: uploaderConfig.SkipCertVerify,
		},
		TLSHandshakeTimeout: ccUploadTLSHandshakeTimeout,
	}

	pollerHttpClient := cfhttp.NewClient()
	pollerHttpClient.Transport = transport

	uploader := ccclient.NewUploader(logger, &http.Client{Transport: transport})
	poller := ccclient.NewPoller(logger, pollerHttpClient, time.Duration(uploaderConfig.CCJobPollingInterval))

	ccUploaderHandler, err := handlers.New(uploader, poller, logger)
	if err != nil {
		logger.Error("router-building-failed", err)
		os.Exit(1)
	}

	return http_server.New(uploaderConfig.ListenAddress, ccUploaderHandler)
}
			pollErrChan chan error

			pollURL                *url.URL
			originalUploadResponse *http.Response
			closeChan              chan struct{}
		)

		BeforeEach(func() {
			closeChan = make(chan struct{})
		})

		JustBeforeEach(func() {
			httpClient := &http.Client{
				Transport: transport,
			}
			u = ccclient.NewPoller(lagertest.NewTestLogger("test"), httpClient, 10*time.Millisecond)
			pollErrChan = make(chan error, 1)
			go func(pec chan error) {
				defer GinkgoRecover()
				pec <- u.Poll(pollURL, originalUploadResponse, closeChan)
			}(pollErrChan)
		})

		Context("when the initial response is invalid", func() {
			BeforeEach(func() {
				originalUploadResponse = responseWithBody("garbage")
			})

			It("returns an error", func() {
				Eventually(pollErrChan).Should(Receive(HaveOccurred()))
			})
	)

	BeforeEach(func() {
		var err error

		logger = lagertest.NewTestLogger("test")

		buffer := bytes.NewBufferString("the file I'm uploading")
		incomingRequest, err = http.NewRequest("POST", "", buffer)
		Expect(err).NotTo(HaveOccurred())
		incomingRequest.Header.Set("Content-MD5", "the-md5")

		fakeCloudController = ghttp.NewServer()

		uploader := ccclient.NewUploader(logger, http.DefaultClient)
		poller := ccclient.NewPoller(logger, http.DefaultClient, 100*time.Millisecond)

		handler, err = handlers.New(uploader, poller, logger)
		Expect(err).NotTo(HaveOccurred())

		postStatusCode = http.StatusCreated
		uploadedBytes = nil
		uploadedFileName = ""
		uploadedHeaders = nil
	})

	AfterEach(func() {
		fakeCloudController.Close()
	})

	Describe("UploadDroplet", func() {