Esempio n. 1
0
func TestCurlFailingRequest(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:  "POST",
		Path:    "/v2/endpoint",
		Matcher: testnet.RequestBodyMatcher(`{"key":"val"}`),
		Response: testnet.TestResponse{
			Status: http.StatusBadRequest,
			Body:   jsonResponse},
	})

	ts, _ := testnet.NewTLSServer(t, []testnet.TestRequest{req})
	defer ts.Close()

	deps := newCurlDependencies()
	deps.config.Target = ts.URL

	repo := NewCloudControllerCurlRepository(deps.config, deps.gateway)
	_, body, _ := repo.Request("POST", "/v2/endpoint", "", `{"key":"val"}`)

	testassert.JSONStringEquals(t, body, jsonResponse)
}
Esempio n. 2
0
func TestCurlGetRequest(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method: "GET",
		Path:   "/v2/endpoint",
		Response: testnet.TestResponse{
			Status: http.StatusOK,
			Body:   jsonResponse},
	})
	ts, handler := testnet.NewTLSServer(t, []testnet.TestRequest{req})
	defer ts.Close()

	deps := newCurlDependencies()
	deps.config.Target = ts.URL

	repo := NewCloudControllerCurlRepository(deps.config, deps.gateway)
	headers, body, apiResponse := repo.Request("GET", "/v2/endpoint", "", "")

	assert.True(t, handler.AllRequestsCalled())
	assert.Contains(t, headers, "200")
	assert.Contains(t, headers, "Content-Type")
	assert.Contains(t, headers, "text/plain")
	testassert.JSONStringEquals(t, body, jsonResponse)
	assert.True(t, apiResponse.IsSuccessful())
}
Esempio n. 3
0
				Body:   expectedJSONResponse},
		})
		ts, handler := testnet.NewServer([]testnet.TestRequest{req})
		defer ts.Close()

		deps := newCurlDependencies()
		deps.config.SetApiEndpoint(ts.URL)

		repo := NewCloudControllerCurlRepository(deps.config, deps.gateway)
		headers, body, apiErr := repo.Request("GET", "/v2/endpoint", "", "")

		Expect(handler).To(testnet.HaveAllRequestsCalled())
		Expect(headers).To(ContainSubstring("200"))
		Expect(headers).To(ContainSubstring("Content-Type"))
		Expect(headers).To(ContainSubstring("text/plain"))
		testassert.JSONStringEquals(body, expectedJSONResponse)
		Expect(apiErr).NotTo(HaveOccurred())
	})

	It("TestCurlPostRequest", func() {
		req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
			Method:  "POST",
			Path:    "/v2/endpoint",
			Matcher: testnet.RequestBodyMatcher(`{"key":"val"}`),
			Response: testnet.TestResponse{
				Status: http.StatusOK,
				Body:   expectedJSONResponse},
		})

		ts, handler := testnet.NewServer([]testnet.TestRequest{req})
		defer ts.Close()
Esempio n. 4
0
				Body:   jsonResponse},
		})
		ts, handler := testnet.NewTLSServer([]testnet.TestRequest{req})
		defer ts.Close()

		deps := newCurlDependencies()
		deps.config.SetApiEndpoint(ts.URL)

		repo := NewCloudControllerCurlRepository(deps.config, deps.gateway)
		headers, body, apiResponse := repo.Request("GET", "/v2/endpoint", "", "")

		Expect(handler.AllRequestsCalled()).To(BeTrue())
		Expect(headers).To(ContainSubstring("200"))
		Expect(headers).To(ContainSubstring("Content-Type"))
		Expect(headers).To(ContainSubstring("text/plain"))
		testassert.JSONStringEquals(body, jsonResponse)
		Expect(apiResponse.IsSuccessful()).To(BeTrue())
	})

	It("TestCurlPostRequest", func() {
		req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
			Method:  "POST",
			Path:    "/v2/endpoint",
			Matcher: testnet.RequestBodyMatcher(`{"key":"val"}`),
			Response: testnet.TestResponse{
				Status: http.StatusOK,
				Body:   jsonResponse},
		})

		ts, handler := testnet.NewTLSServer([]testnet.TestRequest{req})
		defer ts.Close()