Example #1
0
func TestSpacesFindAllWithIncorrectToken(t *testing.T) {
	ts := httptest.NewTLSServer(http.HandlerFunc(multipleSpacesEndpoint))
	defer ts.Close()

	config := &configuration.Configuration{
		AccessToken:  "BEARER incorrect_access_token",
		Target:       ts.URL,
		Organization: cf.Organization{Guid: "some-org-guid"},
	}
	client := NewApiClient(&testhelpers.FakeAuthenticator{})
	repo := NewCloudControllerSpaceRepository(config, client)

	var (
		spaces []cf.Space
		err    error
	)

	// Capture output so debugging info does not show up in test
	// output
	testhelpers.CaptureOutput(func() {
		spaces, err = repo.FindAll()
	})

	assert.Error(t, err)
	assert.Equal(t, 0, len(spaces))
}
Example #2
0
func TestSayWithStringOnly(t *testing.T) {
	ui := new(TerminalUI)
	out := testhelpers.CaptureOutput(func() {
		ui.Say("Hello")
	})

	assert.Equal(t, "Hello\n", out)
}
Example #3
0
func TestSayWithStringWithFormat(t *testing.T) {
	ui := new(TerminalUI)
	out := testhelpers.CaptureOutput(func() {
		ui.Say("Hello %s", "World!")
	})

	assert.Equal(t, "Hello World!\n", out)
}
Example #4
0
func TestOrganizationsFindAllWithIncorrectToken(t *testing.T) {
	ts := httptest.NewTLSServer(http.HandlerFunc(multipleOrgEndpoint))
	defer ts.Close()

	config := &configuration.Configuration{AccessToken: "BEARER incorrect_access_token", Target: ts.URL}
	gateway := net.NewCloudControllerGateway(&testhelpers.FakeAuthenticator{})
	repo := NewCloudControllerOrganizationRepository(config, gateway)

	var (
		organizations []cf.Organization
		err           error
	)

	// Capture output so debugging info does not show up in test
	// output
	testhelpers.CaptureOutput(func() {
		organizations, err = repo.FindAll()
	})

	assert.Error(t, err)
	assert.Equal(t, 0, len(organizations))
}