func TestRunWhenOrganizationExists(t *testing.T) { developmentSpaceFields := cf.SpaceFields{} developmentSpaceFields.Name = "development" stagingSpaceFields := cf.SpaceFields{} stagingSpaceFields.Name = "staging" domainFields := cf.DomainFields{} domainFields.Name = "cfapps.io" cfAppDomainFields := cf.DomainFields{} cfAppDomainFields.Name = "cf-app.com" org := cf.Organization{} org.Name = "my-org" org.Guid = "my-org-guid" org.QuotaDefinition = cf.NewQuotaFields("cantina-quota", 512) org.Spaces = []cf.SpaceFields{developmentSpaceFields, stagingSpaceFields} org.Domains = []cf.DomainFields{domainFields, cfAppDomainFields} reqFactory := &testreq.FakeReqFactory{Organization: org, LoginSuccess: true} args := []string{"my-org"} ui := callShowOrg(t, args, reqFactory) assert.Equal(t, reqFactory.OrganizationName, "my-org") testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Getting info for org", "my-org", "my-user"}, {"OK"}, {"my-org"}, {" domains:", "cfapps.io", "cf-app.com"}, {" quota: ", "cantina-quota", "512M"}, {" spaces:", "development", "staging"}, }) }
func deleteServiceBroker(t *testing.T, confirmation string, args []string) (ui *testterm.FakeUI, reqFactory *testreq.FakeReqFactory, repo *testapi.FakeServiceBrokerRepo) { serviceBroker := cf.ServiceBroker{} serviceBroker.Name = "service-broker-to-delete" serviceBroker.Guid = "service-broker-to-delete-guid" reqFactory = &testreq.FakeReqFactory{LoginSuccess: true} repo = &testapi.FakeServiceBrokerRepo{FindByNameServiceBroker: serviceBroker} ui = &testterm.FakeUI{ Inputs: []string{confirmation}, } token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{ Username: "******", }) assert.NoError(t, err) space2 := cf.SpaceFields{} space2.Name = "my-space" org2 := cf.OrganizationFields{} org2.Name = "my-org" config := &configuration.Configuration{ SpaceFields: space2, OrganizationFields: org2, AccessToken: token, } ctxt := testcmd.NewContext("delete-service-broker", args) cmd := NewDeleteServiceBroker(ui, config, repo) testcmd.RunCommand(cmd, ctxt, reqFactory) return }
func TestClearTokens(t *testing.T) { org := cf.OrganizationFields{} org.Name = "my-org" space := cf.SpaceFields{} space.Name = "my-space" repo := NewConfigurationDiskRepository() config := repo.loadDefaultConfig(t) defer repo.restoreConfig(t) config.Target = "http://api.example.com" config.RefreshToken = "some old refresh token" config.AccessToken = "some old access token" config.OrganizationFields = org config.SpaceFields = space repo.Save() err := repo.ClearTokens() assert.NoError(t, err) repo.Save() savedConfig, err := repo.Get() assert.NoError(t, err) assert.Equal(t, savedConfig.Target, "http://api.example.com") assert.Empty(t, savedConfig.AccessToken) assert.Empty(t, savedConfig.RefreshToken) assert.Equal(t, savedConfig.OrganizationFields, org) assert.Equal(t, savedConfig.SpaceFields, space) }
func callListRoutes(t *testing.T, args []string, reqFactory *testreq.FakeReqFactory, routeRepo *testapi.FakeRouteRepository) (ui *testterm.FakeUI) { ui = &testterm.FakeUI{} ctxt := testcmd.NewContext("routes", args) token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{ Username: "******", }) assert.NoError(t, err) space := cf.SpaceFields{} space.Name = "my-space" org := cf.OrganizationFields{} org.Name = "my-org" config := &configuration.Configuration{ SpaceFields: space, OrganizationFields: org, AccessToken: token, } cmd := NewListRoutes(ui, config, routeRepo) testcmd.RunCommand(cmd, ctxt, reqFactory) return }
func callListQuotas(t *testing.T, reqFactory *testreq.FakeReqFactory, quotaRepo *testapi.FakeQuotaRepository) (fakeUI *testterm.FakeUI) { fakeUI = &testterm.FakeUI{} ctxt := testcmd.NewContext("quotas", []string{}) token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{ Username: "******", }) assert.NoError(t, err) spaceFields := cf.SpaceFields{} spaceFields.Name = "my-space" orgFields := cf.OrganizationFields{} orgFields.Name = "my-org" config := &configuration.Configuration{ SpaceFields: spaceFields, OrganizationFields: orgFields, AccessToken: token, } cmd := organization.NewListQuotas(fakeUI, config, quotaRepo) testcmd.RunCommand(cmd, ctxt, reqFactory) return }
func deleteApp(t *testing.T, confirmation string, args []string) (ui *testterm.FakeUI, reqFactory *testreq.FakeReqFactory, appRepo *testapi.FakeApplicationRepository) { app := cf.Application{} app.Name = "app-to-delete" app.Guid = "app-to-delete-guid" reqFactory = &testreq.FakeReqFactory{} appRepo = &testapi.FakeApplicationRepository{ReadApp: app} ui = &testterm.FakeUI{ Inputs: []string{confirmation}, } token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{ Username: "******", }) assert.NoError(t, err) org := cf.OrganizationFields{} org.Name = "my-org" space := cf.SpaceFields{} space.Name = "my-space" config := &configuration.Configuration{ SpaceFields: space, OrganizationFields: org, AccessToken: token, } ctxt := testcmd.NewContext("delete", args) cmd := NewDeleteApp(ui, config, appRepo) testcmd.RunCommand(cmd, ctxt, reqFactory) return }
func callDomainMapper(t *testing.T, shouldMap bool, args []string, reqFactory *testreq.FakeReqFactory, domainRepo *testapi.FakeDomainRepository) (ui *testterm.FakeUI) { cmdName := "map-domain" if !shouldMap { cmdName = "unmap-domain" } ctxt := testcmd.NewContext(cmdName, args) ui = &testterm.FakeUI{} token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{ Username: "******", }) assert.NoError(t, err) orgFields := cf.OrganizationFields{} orgFields.Name = "my-org" spaceFields := cf.SpaceFields{} spaceFields.Name = "my-space" config := &configuration.Configuration{ SpaceFields: spaceFields, OrganizationFields: orgFields, AccessToken: token, } cmd := domain.NewDomainMapper(ui, config, domainRepo, shouldMap) testcmd.RunCommand(cmd, ctxt, reqFactory) return }
func callDeleteDomain(t *testing.T, args []string, inputs []string, reqFactory *testreq.FakeReqFactory, domainRepo *testapi.FakeDomainRepository) (ui *testterm.FakeUI) { ctxt := testcmd.NewContext("delete-domain", args) ui = &testterm.FakeUI{ Inputs: inputs, } token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{ Username: "******", }) assert.NoError(t, err) spaceFields := cf.SpaceFields{} spaceFields.Name = "my-space" orgFields := cf.OrganizationFields{} orgFields.Name = "my-org" config := &configuration.Configuration{ SpaceFields: spaceFields, OrganizationFields: orgFields, AccessToken: token, } cmd := domain.NewDeleteDomain(ui, config, domainRepo) testcmd.RunCommand(cmd, ctxt, reqFactory) return }
func deleteOrg(t *testing.T, confirmation string, args []string, orgRepo *testapi.FakeOrgRepository) (ui *testterm.FakeUI) { reqFactory := &testreq.FakeReqFactory{} configRepo := &testconfig.FakeConfigRepository{} ui = &testterm.FakeUI{ Inputs: []string{confirmation}, } ctxt := testcmd.NewContext("delete-org", args) token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{ Username: "******", }) assert.NoError(t, err) spaceFields := cf.SpaceFields{} spaceFields.Name = "my-space" orgFields := cf.OrganizationFields{} orgFields.Name = "my-org" config := &configuration.Configuration{ SpaceFields: spaceFields, OrganizationFields: orgFields, AccessToken: token, } cmd := NewDeleteOrg(ui, config, orgRepo, configRepo) testcmd.RunCommand(cmd, ctxt, reqFactory) return }
func TestDeleteTargetedOrganizationClearsConfig(t *testing.T) { configRepo := &testconfig.FakeConfigRepository{} config, _ := configRepo.Get() organizationFields := cf.OrganizationFields{} organizationFields.Name = "org-to-delete" organizationFields.Guid = "org-to-delete-guid" config.OrganizationFields = organizationFields spaceFields := cf.SpaceFields{} spaceFields.Name = "space-to-delete" config.SpaceFields = spaceFields configRepo.Save() org := cf.Organization{} org.OrganizationFields = organizationFields orgRepo := &testapi.FakeOrgRepository{FindByNameOrganization: org} deleteOrg(t, "Yes", []string{"org-to-delete"}, orgRepo) updatedConfig, err := configRepo.Get() assert.NoError(t, err) assert.Equal(t, updatedConfig.OrganizationFields, cf.OrganizationFields{}) assert.Equal(t, updatedConfig.SpaceFields, cf.SpaceFields{}) }
func TestEmptyServicesList(t *testing.T) { serviceInstances := []cf.ServiceInstance{} serviceSummaryRepo := &testapi.FakeServiceSummaryRepo{ GetSummariesInCurrentSpaceInstances: serviceInstances, } ui := &testterm.FakeUI{} token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{ Username: "******", }) assert.NoError(t, err) org := cf.OrganizationFields{} org.Name = "my-org" space := cf.SpaceFields{} space.Name = "my-space" config := &configuration.Configuration{ SpaceFields: space, OrganizationFields: org, AccessToken: token, } cmd := NewListServices(ui, config, serviceSummaryRepo) cmd.Run(testcmd.NewContext("services", []string{})) testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Getting services in org", "my-org", "my-space", "my-user"}, {"OK"}, {"No services found"}, }) testassert.SliceDoesNotContain(t, ui.Outputs, testassert.Lines{ {"name", "service", "plan", "bound apps"}, }) }
func callRenameOrg(t *testing.T, args []string, reqFactory *testreq.FakeReqFactory, orgRepo *testapi.FakeOrgRepository) (ui *testterm.FakeUI) { ui = new(testterm.FakeUI) ctxt := testcmd.NewContext("rename-org", args) token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{ Username: "******", }) assert.NoError(t, err) spaceFields := cf.SpaceFields{} spaceFields.Name = "my-space" orgFields := cf.OrganizationFields{} orgFields.Name = "my-org" config := &configuration.Configuration{ SpaceFields: spaceFields, OrganizationFields: orgFields, AccessToken: token, } cmd := organization.NewRenameOrg(ui, config, orgRepo) testcmd.RunCommand(cmd, ctxt, reqFactory) return }
func deleteWithConfirmation(t *testing.T, confirmation string) (ui *testterm.FakeUI, userRepo *testapi.FakeUserRepository) { ui = &testterm.FakeUI{ Inputs: []string{confirmation}, } user2 := cf.UserFields{} user2.Username = "******" user2.Guid = "my-found-user-guid" userRepo = &testapi.FakeUserRepository{ FindByUsernameUserFields: user2, } token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{ Username: "******", }) assert.NoError(t, err) org2 := cf.OrganizationFields{} org2.Name = "my-org" space2 := cf.SpaceFields{} space2.Name = "my-space" config := &configuration.Configuration{ SpaceFields: space2, OrganizationFields: org2, AccessToken: token, } cmd := NewDeleteUser(ui, config, userRepo) ctxt := testcmd.NewContext("delete-user", []string{"my-user"}) reqFactory := &testreq.FakeReqFactory{LoginSuccess: true} testcmd.RunCommand(cmd, ctxt, reqFactory) return }
func TestUpdateEndpointWhenUrlIsValidHttpsInfoEndpoint(t *testing.T) { configRepo := testconfig.FakeConfigRepository{} configRepo.Delete() configRepo.Login() ts, repo := createEndpointRepoForUpdate(configRepo, validApiInfoEndpoint) defer ts.Close() org := cf.OrganizationFields{} org.Name = "my-org" org.Guid = "my-org-guid" space := cf.SpaceFields{} space.Name = "my-space" space.Guid = "my-space-guid" config, _ := configRepo.Get() config.OrganizationFields = org config.SpaceFields = space repo.UpdateEndpoint(ts.URL) savedConfig := testconfig.SavedConfiguration assert.Equal(t, savedConfig.AccessToken, "") assert.Equal(t, savedConfig.AuthorizationEndpoint, "https://login.example.com") assert.Equal(t, savedConfig.Target, ts.URL) assert.Equal(t, savedConfig.ApiVersion, "42.0.0") assert.False(t, savedConfig.HasOrganization()) assert.False(t, savedConfig.HasSpace()) }
func TestLogoutClearsAccessTokenOrgAndSpace(t *testing.T) { org := cf.OrganizationFields{} org.Name = "MyOrg" space := cf.SpaceFields{} space.Name = "MySpace" configRepo := &testconfig.FakeConfigRepository{} config, _ := configRepo.Get() config.AccessToken = "MyAccessToken" config.OrganizationFields = org config.SpaceFields = space ui := new(testterm.FakeUI) l := commands.NewLogout(ui, configRepo) l.Run(nil) updatedConfig, err := configRepo.Get() assert.NoError(t, err) assert.Empty(t, updatedConfig.AccessToken) assert.Equal(t, updatedConfig.OrganizationFields, cf.OrganizationFields{}) assert.Equal(t, updatedConfig.SpaceFields, cf.SpaceFields{}) }
func TestClearSession(t *testing.T) { withFakeHome(t, func() { repo := NewConfigurationDiskRepository() config, err := repo.Get() assert.NoError(t, err) config.Target = "http://api.example.com" config.RefreshToken = "some old refresh token" config.AccessToken = "some old access token" org := cf.OrganizationFields{} org.Name = "my-org" space := cf.SpaceFields{} space.Name = "my-space" repo.Save() err = repo.ClearSession() assert.NoError(t, err) repo.Save() savedConfig, err := repo.Get() assert.NoError(t, err) assert.Equal(t, savedConfig.Target, "http://api.example.com") assert.Empty(t, savedConfig.AccessToken) assert.Empty(t, savedConfig.RefreshToken) assert.Equal(t, savedConfig.OrganizationFields, cf.OrganizationFields{}) assert.Equal(t, savedConfig.SpaceFields, cf.SpaceFields{}) }) }
func TestUpdateEndpointWhenUrlIsAlreadyTargeted(t *testing.T) { configRepo := testconfig.FakeConfigRepository{} configRepo.Delete() configRepo.Login() ts, repo := createEndpointRepoForUpdate(configRepo, validApiInfoEndpoint) defer ts.Close() org := cf.OrganizationFields{} org.Name = "my-org" org.Guid = "my-org-guid" space := cf.SpaceFields{} space.Name = "my-space" space.Guid = "my-space-guid" config, _ := configRepo.Get() config.Target = ts.URL config.AccessToken = "some access token" config.RefreshToken = "some refresh token" config.OrganizationFields = org config.SpaceFields = space repo.UpdateEndpoint(ts.URL) assert.Equal(t, config.OrganizationFields, org) assert.Equal(t, config.SpaceFields, space) assert.Equal(t, config.AccessToken, "some access token") assert.Equal(t, config.RefreshToken, "some refresh token") }
func callRenameService(t *testing.T, args []string, reqFactory *testreq.FakeReqFactory) (ui *testterm.FakeUI, serviceRepo *testapi.FakeServiceRepo) { ui = &testterm.FakeUI{} serviceRepo = &testapi.FakeServiceRepo{} token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{ Username: "******", }) assert.NoError(t, err) org := cf.OrganizationFields{} org.Name = "my-org" space := cf.SpaceFields{} space.Name = "my-space" config := &configuration.Configuration{ SpaceFields: space, OrganizationFields: org, AccessToken: token, } cmd := NewRenameService(ui, config, serviceRepo) ctxt := testcmd.NewContext("rename-service", args) testcmd.RunCommand(cmd, ctxt, reqFactory) return }
func callStacks(t *testing.T, stackRepo *testapi.FakeStackRepository) (ui *testterm.FakeUI) { ui = &testterm.FakeUI{} ctxt := testcmd.NewContext("stacks", []string{}) token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{ Username: "******", }) assert.NoError(t, err) space := cf.SpaceFields{} space.Name = "my-space" org := cf.OrganizationFields{} org.Name = "my-org" config := &configuration.Configuration{ SpaceFields: space, OrganizationFields: org, AccessToken: token, } cmd := NewStacks(ui, config, stackRepo) testcmd.RunCommand(cmd, ctxt, nil) return }
func TestCreateRoute(t *testing.T) { space := cf.SpaceFields{} space.Guid = "my-space-guid" space.Name = "my-space" domain := cf.DomainFields{} domain.Guid = "domain-guid" domain.Name = "example.com" reqFactory := &testreq.FakeReqFactory{ LoginSuccess: true, TargetedOrgSuccess: true, Domain: cf.Domain{DomainFields: domain}, Space: cf.Space{SpaceFields: space}, } routeRepo := &testapi.FakeRouteRepository{} ui := callCreateRoute(t, []string{"-n", "host", "my-space", "example.com"}, reqFactory, routeRepo) testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Creating route", "host.example.com", "my-org", "my-space", "my-user"}, {"OK"}, }) assert.Equal(t, routeRepo.CreateInSpaceHost, "host") assert.Equal(t, routeRepo.CreateInSpaceDomainGuid, "domain-guid") assert.Equal(t, routeRepo.CreateInSpaceSpaceGuid, "my-space-guid") }
func TestDeleteUntargetedOrganizationDoesNotClearConfig(t *testing.T) { org := cf.Organization{} org.Name = "org-to-delete" org.Guid = "org-to-delete-guid" orgRepo := &testapi.FakeOrgRepository{FindByNameOrganization: org} configRepo := &testconfig.FakeConfigRepository{} config, _ := configRepo.Get() otherOrgFields := cf.OrganizationFields{} otherOrgFields.Guid = "some-other-org-guid" otherOrgFields.Name = "some-other-org" config.OrganizationFields = otherOrgFields spaceFields := cf.SpaceFields{} spaceFields.Name = "some-other-space" config.SpaceFields = spaceFields configRepo.Save() deleteOrg(t, "Yes", []string{"org-to-delete"}, orgRepo) updatedConfig, err := configRepo.Get() assert.NoError(t, err) assert.Equal(t, updatedConfig.OrganizationFields.Name, "some-other-org") assert.Equal(t, updatedConfig.SpaceFields.Name, "some-other-space") }
func callDeleteServiceAuthToken(t *testing.T, args []string, inputs []string, reqFactory *testreq.FakeReqFactory, authTokenRepo *testapi.FakeAuthTokenRepo) (ui *testterm.FakeUI) { ui = &testterm.FakeUI{ Inputs: inputs, } token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{ Username: "******", }) assert.NoError(t, err) org := cf.OrganizationFields{} org.Name = "my-org" space := cf.SpaceFields{} space.Name = "my-space" config := &configuration.Configuration{ SpaceFields: space, OrganizationFields: org, AccessToken: token, } cmd := NewDeleteServiceAuthToken(ui, config, authTokenRepo) ctxt := testcmd.NewContext("delete-service-auth-token", args) testcmd.RunCommand(cmd, ctxt, reqFactory) return }
func TestServices(t *testing.T) { plan := cf.ServicePlanFields{} plan.Guid = "spark-guid" plan.Name = "spark" offering := cf.ServiceOfferingFields{} offering.Label = "cleardb" serviceInstance := cf.ServiceInstance{} serviceInstance.Name = "my-service-1" serviceInstance.ServicePlan = plan serviceInstance.ApplicationNames = []string{"cli1", "cli2"} serviceInstance.ServiceOffering = offering plan2 := cf.ServicePlanFields{} plan2.Guid = "spark-guid-2" plan2.Name = "spark-2" serviceInstance2 := cf.ServiceInstance{} serviceInstance2.Name = "my-service-2" serviceInstance2.ServicePlan = plan2 serviceInstance2.ApplicationNames = []string{"cli1"} serviceInstance2.ServiceOffering = offering serviceInstance3 := cf.ServiceInstance{} serviceInstance3.Name = "my-service-provided-by-user" serviceInstances := []cf.ServiceInstance{serviceInstance, serviceInstance2, serviceInstance3} serviceSummaryRepo := &testapi.FakeServiceSummaryRepo{ GetSummariesInCurrentSpaceInstances: serviceInstances, } ui := &testterm.FakeUI{} token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{ Username: "******", }) assert.NoError(t, err) org := cf.OrganizationFields{} org.Name = "my-org" space := cf.SpaceFields{} space.Name = "my-space" config := &configuration.Configuration{ SpaceFields: space, OrganizationFields: org, AccessToken: token, } cmd := NewListServices(ui, config, serviceSummaryRepo) cmd.Run(testcmd.NewContext("services", []string{})) testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Getting services in org", "my-org", "my-space", "my-user"}, {"OK"}, {"my-service-1", "cleardb", "spark", "cli1, cli2"}, {"my-service-2", "cleardb", "spark-2", "cli1"}, {"my-service-provided-by-user", "user-provided"}, }) }
func TestListDomains(t *testing.T) { orgFields := cf.OrganizationFields{} orgFields.Name = "my-org" orgFields.Guid = "my-org-guid" reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true, OrganizationFields: orgFields} domain1 := cf.Domain{} domain1.Shared = true domain1.Name = "Domain1" domain2 := cf.Domain{} domain2.Shared = false domain2.Name = "Domain2" space1 := cf.SpaceFields{} space1.Name = "my-space" space2 := cf.SpaceFields{} space2.Name = "my-space-2" domain2.Spaces = []cf.SpaceFields{space1, space2} domain3 := cf.Domain{} domain3.Shared = false domain3.Name = "Domain3" domainRepo := &testapi.FakeDomainRepository{ ListDomainsForOrgDomains: []cf.Domain{domain1, domain2, domain3}, } ui := callListDomains(t, []string{}, reqFactory, domainRepo) assert.Equal(t, domainRepo.ListDomainsForOrgDomainsGuid, "my-org-guid") testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Getting domains in org", "my-org", "my-user"}, {"name", "status", "spaces"}, {"Domain1", "shared"}, {"Domain2", "owned", "my-space", "my-space-2"}, {"Domain3", "reserved"}, }) }
func createBuildpackRepo(t *testing.T, requests ...testnet.TestRequest) (ts *httptest.Server, handler *testnet.TestHandler, repo BuildpackRepository) { ts, handler = testnet.NewTLSServer(t, requests) space := cf.SpaceFields{} space.Name = "my-space" space.Guid = "my-space-guid" config := &configuration.Configuration{ AccessToken: "BEARER my_access_token", Target: ts.URL, SpaceFields: space, } gateway := net.NewCloudControllerGateway() repo = NewCloudControllerBuildpackRepository(config, gateway) return }
func TestMarketplaceServices(t *testing.T) { plan := cf.ServicePlanFields{} plan.Name = "service-plan-a" plan2 := cf.ServicePlanFields{} plan2.Name = "service-plan-b" plan3 := cf.ServicePlanFields{} plan3.Name = "service-plan-c" plan4 := cf.ServicePlanFields{} plan4.Name = "service-plan-d" offering := cf.ServiceOffering{} offering.Label = "zzz-my-service-offering" offering.Description = "service offering 1 description" offering.Plans = []cf.ServicePlanFields{plan, plan2} offering2 := cf.ServiceOffering{} offering2.Label = "aaa-my-service-offering" offering2.Description = "service offering 2 description" offering2.Plans = []cf.ServicePlanFields{plan3, plan4} serviceOfferings := []cf.ServiceOffering{offering, offering2} serviceRepo := &testapi.FakeServiceRepo{ServiceOfferings: serviceOfferings} token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{ Username: "******", }) assert.NoError(t, err) org := cf.OrganizationFields{} org.Name = "my-org" org.Guid = "my-org-guid" space := cf.SpaceFields{} space.Name = "my-space" space.Guid = "my-space-guid" config := &configuration.Configuration{ SpaceFields: space, OrganizationFields: org, AccessToken: token, } ui := callMarketplaceServices(t, config, serviceRepo) testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Getting services from marketplace in org", "my-org", "my-space", "my-user"}, {"OK"}, {"service", "plans", "description"}, {"aaa-my-service-offering", "service offering 2 description", "service-plan-c", "service-plan-d"}, {"zzz-my-service-offering", "service offering 1 description", "service-plan-a", "service-plan-b"}, }) }
func TestSetSpace(t *testing.T) { repo := NewConfigurationDiskRepository() repo.loadDefaultConfig(t) defer repo.restoreConfig(t) space := cf.SpaceFields{} space.Name = "my-space" space.Guid = "my-space-guid" err := repo.SetSpace(space) assert.NoError(t, err) repo.Save() savedConfig, err := repo.Get() assert.NoError(t, err) assert.Equal(t, savedConfig.SpaceFields, space) }
func TestSetSpace(t *testing.T) { withFakeHome(t, func() { repo := NewConfigurationDiskRepository() repo.Get() space := cf.SpaceFields{} space.Name = "my-space" space.Guid = "my-space-guid" err := repo.SetSpace(space) assert.NoError(t, err) repo.Save() savedConfig, err := repo.Get() assert.NoError(t, err) assert.Equal(t, savedConfig.SpaceFields, space) }) }
func TestRouteCreator(t *testing.T) { space := cf.SpaceFields{} space.Guid = "my-space-guid" space.Name = "my-space" domain := cf.DomainFields{} domain.Guid = "domain-guid" domain.Name = "example.com" createdRoute := cf.Route{} createdRoute.Host = "my-host" createdRoute.Guid = "my-route-guid" routeRepo := &testapi.FakeRouteRepository{ CreateInSpaceCreatedRoute: createdRoute, } ui := new(testterm.FakeUI) token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{ Username: "******", }) assert.NoError(t, err) org := cf.OrganizationFields{} org.Name = "my-org" config := &configuration.Configuration{ OrganizationFields: org, AccessToken: token, } cmd := NewCreateRoute(ui, config, routeRepo) route, apiResponse := cmd.CreateRoute("my-host", domain, space) assert.Equal(t, route.Guid, createdRoute.Guid) assert.True(t, apiResponse.IsSuccessful()) testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Creating route", "my-host.example.com", "my-org", "my-space", "my-user"}, {"OK"}, }) assert.Equal(t, routeRepo.CreateInSpaceHost, "my-host") assert.Equal(t, routeRepo.CreateInSpaceDomainGuid, "domain-guid") assert.Equal(t, routeRepo.CreateInSpaceSpaceGuid, "my-space-guid") }
func TestDeleteSpaceWhenSpaceNotTargeted(t *testing.T) { reqFactory := defaultDeleteSpaceReqFactory() spaceRepo := &testapi.FakeSpaceRepository{} configRepo := &testconfig.FakeConfigRepository{} config, _ := configRepo.Get() otherSpace := cf.SpaceFields{} otherSpace.Name = "do-not-delete" otherSpace.Guid = "do-not-delete-guid" config.SpaceFields = otherSpace configRepo.Save() ui := &testterm.FakeUI{} ctxt := testcmd.NewContext("delete", []string{"-f", "space-to-delete"}) cmd := NewDeleteSpace(ui, config, spaceRepo, configRepo) testcmd.RunCommand(cmd, ctxt, reqFactory) config, _ = configRepo.Get() assert.Equal(t, config.HasSpace(), true) }