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)) }
func TestSayWithStringOnly(t *testing.T) { ui := new(TerminalUI) out := testhelpers.CaptureOutput(func() { ui.Say("Hello") }) assert.Equal(t, "Hello\n", out) }
func TestSayWithStringWithFormat(t *testing.T) { ui := new(TerminalUI) out := testhelpers.CaptureOutput(func() { ui.Say("Hello %s", "World!") }) assert.Equal(t, "Hello World!\n", out) }
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)) }