示例#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"))
	fakehttp "github.com/cloudfoundry/bosh-utils/http/fakes"

	boshlog "github.com/cloudfoundry/bosh-utils/logger"
)

var _ = Describe("RequestRetryable", func() {
	Describe("Attempt", func() {
		var (
			requestRetryable RequestRetryable
			request          *http.Request
			fakeClient       *fakehttp.FakeClient
		)

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

			request = &http.Request{
				Body: ioutil.NopCloser(strings.NewReader("fake-request-body")),
			}

			requestRetryable = NewRequestRetryable(request, fakeClient, logger)
		})

		It("calls Do on the delegate", func() {
			fakeClient.SetMessage("fake-response-body")
			fakeClient.StatusCode = 200

			_, err := requestRetryable.Attempt()
			Expect(err).ToNot(HaveOccurred())