Example #1
0
				expectedAuthEncoded := base64.URLEncoding.EncodeToString([]byte("fake-user:fake-pass"))
				Expect(r.Header.Get("Authorization")).To(Equal(fmt.Sprintf("Basic %s", expectedAuthEncoded)))
			})
			ts := httptest.NewServer(handler)
			defer ts.Close()

			client := newRealClient(ts.Listener.Addr().String())

			err := client.StartService("test-service")
			Expect(err).ToNot(HaveOccurred())
			Expect(calledMonit).To(BeTrue())
		})

		It("uses the shortClient to send a start request", func() {
			shortClient := fakehttp.NewFakeClient()
			longClient := fakehttp.NewFakeClient()
			client := newFakeClient(shortClient, longClient)

			shortClient.StatusCode = 200

			err := client.StartService("test-service")
			Expect(err).ToNot(HaveOccurred())

			Expect(shortClient.CallCount).To(Equal(1))
			Expect(longClient.CallCount).To(Equal(0))

			req := shortClient.Requests[0]
			Expect(req.URL.Host).To(Equal("agent.example.com"))
			Expect(req.URL.Path).To(Equal("/test-service"))
			Expect(req.Method).To(Equal("POST"))
Example #2
0
	. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/ginkgo"
	. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/gomega"

	. "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/http"
)

var _ = Describe("RetryClient", func() {
	Describe("Do", func() {
		var (
			retryClient Client
			maxAttempts int
			fakeClient  *fakehttp.FakeClient
		)

		BeforeEach(func() {
			fakeClient = fakehttp.NewFakeClient()
			logger := boshlog.NewLogger(boshlog.LevelNone)
			maxAttempts = 7

			retryClient = NewRetryClient(fakeClient, uint(maxAttempts), 0, logger)
		})

		It("returns response from retryable request", func() {
			fakeClient.SetMessage("fake-response-body")
			fakeClient.StatusCode = 204

			req := &http.Request{}
			resp, err := retryClient.Do(req)
			Expect(err).ToNot(HaveOccurred())

			Expect(readString(resp.Body)).To(Equal("fake-response-body"))