Expect(runCommand("my-space")).To(BeFalse()) }) It("does not pass requirements if space does not exist", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) requirementsFactory.NewTargetedOrgRequirementReturns(new(requirementsfakes.FakeTargetedOrgRequirement)) spaceReq := new(requirementsfakes.FakeSpaceRequirement) spaceReq.ExecuteReturns(errors.New("no space")) requirementsFactory.NewSpaceRequirementReturns(spaceReq) Expect(runCommand("my-space")).To(BeFalse()) }) }) Describe("allow-space-ssh", func() { var space models.Space BeforeEach(func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) requirementsFactory.NewTargetedOrgRequirementReturns(new(requirementsfakes.FakeTargetedOrgRequirement)) space = models.Space{} space.Name = "the-space-name" space.GUID = "the-space-guid" spaceReq := new(requirementsfakes.FakeSpaceRequirement) spaceReq.GetSpaceReturns(space) requirementsFactory.NewSpaceRequirementReturns(spaceReq) }) Context("when allow_ssh is already set to the true", func() { BeforeEach(func() {
orgRepo.FindByNameReturns(org, nil) config.SetOrganizationFields(models.OrganizationFields{Name: org.Name, GUID: org.GUID}) }) It("it updates the organization in the config", func() { callTarget([]string{"-o", "my-organization"}) Expect(orgRepo.FindByNameCallCount()).To(Equal(1)) Expect(orgRepo.FindByNameArgsForCall(0)).To(Equal("my-organization")) Expect(ui.ShowConfigurationCalled).To(BeTrue()) Expect(config.OrganizationFields().GUID).To(Equal("my-organization-guid")) }) It("updates the space in the config", func() { space := models.Space{} space.Name = "my-space" space.GUID = "my-space-guid" spaceRepo.FindByNameReturns(space, nil) callTarget([]string{"-s", "my-space"}) Expect(spaceRepo.FindByNameCallCount()).To(Equal(1)) Expect(spaceRepo.FindByNameArgsForCall(0)).To(Equal("my-space")) Expect(config.SpaceFields().GUID).To(Equal("my-space-guid")) Expect(ui.ShowConfigurationCalled).To(BeTrue()) }) It("updates both the organization and the space in the config", func() { space := models.Space{}
It("fails if we cannot obtain the target application", func() { appRepo.ReadFromSpaceReturns(models.Application{}, errors.New("could not find target app")) runCommand("source-app", "target-app") Expect(ui.Outputs()).To(ContainSubstrings( []string{"FAILED"}, []string{"could not find target app"}, )) }) }) }) Describe("when a space is provided, but not an org", func() { It("send the correct target appplication for the current org and target space", func() { space := models.Space{} space.Name = "space-name" space.GUID = "model-space-guid" spaceRepo.FindByNameReturns(space, nil) runCommand("-s", "space-name", "source-app", "target-app") targetAppName, spaceGUID := appRepo.ReadFromSpaceArgsForCall(0) Expect(targetAppName).To(Equal("target-app")) Expect(spaceGUID).To(Equal("model-space-guid")) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Copying source from app", "source-app", "to target app", "target-app", "in org my-org / space space-name as my-user..."}, []string{"Note: this may take some time"}, []string{"OK"}, ))
deps = commandregistry.Dependency{ UI: ui, Config: configRepo, RepoLocator: repoLocator, } cmd = &route.CreateRoute{} cmd.SetDependency(deps, false) flagContext = flags.NewFlagContext(cmd.MetaData().Flags) factory = new(requirementsfakes.FakeFactory) spaceRequirement = new(requirementsfakes.FakeSpaceRequirement) space := models.Space{} space.GUID = "space-guid" space.Name = "space-name" spaceRequirement.GetSpaceReturns(space) factory.NewSpaceRequirementReturns(spaceRequirement) domainRequirement = new(requirementsfakes.FakeDomainRequirement) domainRequirement.GetDomainReturns(models.DomainFields{ GUID: "domain-guid", Name: "domain-name", }) factory.NewDomainRequirementReturns(domainRequirement) minAPIVersionRequirement = &passingRequirement{} factory.NewMinAPIVersionRequirementReturns(minAPIVersionRequirement) })
It("fails with usage when not invoked with exactly two args", func() { runCommand("my-org") Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage", "Requires arguments"}, )) }) Context("when logged in and given some users in the org and space", func() { BeforeEach(func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) org := models.Organization{} org.Name = "Org1" org.GUID = "org1-guid" space := models.Space{} space.Name = "Space1" space.GUID = "space1-guid" organizationReq := new(requirementsfakes.FakeOrganizationRequirement) organizationReq.GetOrganizationReturns(org) requirementsFactory.NewOrganizationRequirementReturns(organizationReq) spaceRepo.FindByNameInOrgReturns(space, nil) user := models.UserFields{} user.Username = "******" user2 := models.UserFields{} user2.Username = "******" user3 := models.UserFields{} user3.Username = "******" user4 := models.UserFields{}
"code.cloudfoundry.org/cli/cf/api/spaces/spacesfakes" "code.cloudfoundry.org/cli/cf/models" . "code.cloudfoundry.org/cli/cf/requirements" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("SpaceRequirement", func() { var spaceRepo *spacesfakes.FakeSpaceRepository BeforeEach(func() { spaceRepo = new(spacesfakes.FakeSpaceRepository) }) Context("when a space with the given name exists", func() { It("succeeds", func() { space := models.Space{} space.Name = "awesome-sauce-space" space.GUID = "my-space-guid" spaceRepo.FindByNameReturns(space, nil) spaceReq := NewSpaceRequirement("awesome-sauce-space", spaceRepo) err := spaceReq.Execute() Expect(err).NotTo(HaveOccurred()) Expect(spaceReq.GetSpace()).To(Equal(space)) Expect(spaceRepo.FindByNameArgsForCall(0)).To(Equal("awesome-sauce-space")) }) }) Context("when a space with the given name does not exist", func() { It("errors", func() {
}) It("doesn't call CC", func() { Expect(userRepo.UnsetSpaceRoleByGUIDCallCount()).To(BeZero()) Expect(userRepo.UnsetSpaceRoleByUsernameCallCount()).To(BeZero()) }) It("return an error", func() { Expect(err).To(HaveOccurred()) Expect(err.Error()).To(Equal("space-repo-error")) }) }) Context("when the space is found", func() { BeforeEach(func() { space := models.Space{} space.GUID = "the-space-guid" space.Name = "the-space-name" space.Organization = org.OrganizationFields spaceRepo.FindByNameInOrgReturns(space, nil) }) Context("when the UserRequirement returns a user with a GUID", func() { BeforeEach(func() { userFields := models.UserFields{GUID: "the-user-guid", Username: "******"} userRequirement.GetUserReturns(userFields) }) It("tells the user it is removing the role", func() { Expect(err).NotTo(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings(
Config.SetAccessToken("my_access_token") Config.SetRefreshToken("my_refresh_token") return nil } endpointRepo = new(coreconfigfakes.FakeEndpointRepository) minCLIVersion = "1.0.0" minRecommendedCLIVersion = "1.0.0" org = models.Organization{} org.Name = "my-new-org" org.GUID = "my-new-org-guid" orgRepo = &organizationsfakes.FakeOrganizationRepository{} orgRepo.ListOrgsReturns([]models.Organization{org}, nil) space := models.Space{} space.GUID = "my-space-guid" space.Name = "my-space" spaceRepo = new(spacesfakes.FakeSpaceRepository) spaceRepo.ListSpacesStub = listSpacesStub([]models.Space{space}) authRepo.GetLoginPromptsAndSaveUAAServerURLReturns(map[string]coreconfig.AuthPrompt{ "username": { DisplayName: "Username", Type: coreconfig.AuthPromptTypeText, }, "password": { DisplayName: "Password", Type: coreconfig.AuthPromptTypePassword, },
} } return nil } } Describe("when invoked by a plugin", func() { var ( pluginModels []plugin_models.GetSpaces_Model ) BeforeEach(func() { pluginModels = []plugin_models.GetSpaces_Model{} deps.PluginModels.Spaces = &pluginModels space := models.Space{} space.Name = "space1" space.GUID = "123" space2 := models.Space{} space2.Name = "space2" space2.GUID = "456" spaceRepo.ListSpacesStub = listSpacesStub([]models.Space{space, space2}) requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) requirementsFactory.NewTargetedOrgRequirementReturns(new(requirementsfakes.FakeTargetedOrgRequirement)) }) It("populates the plugin models upon execution", func() { testcmd.RunCLICommand("spaces", []string{}, requirementsFactory, updateCommandDependency, true, ui) runCommand() Expect(pluginModels[0].Name).To(Equal("space1"))
Expect(callRenameSpace([]string{"my-space", "my-new-space"})).To(BeFalse()) }) }) Describe("when the user provides fewer than two args", func() { It("fails with usage", func() { callRenameSpace([]string{"foo"}) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage", "Requires", "arguments"}, )) }) }) Describe("when the user is logged in and has provided an old and new space name", func() { var space models.Space BeforeEach(func() { requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) requirementsFactory.NewTargetedOrgRequirementReturns(new(requirementsfakes.FakeTargetedOrgRequirement)) space = models.Space{} space.Name = "the-old-space-name" space.GUID = "the-old-space-guid" spaceReq := new(requirementsfakes.FakeSpaceRequirement) spaceReq.GetSpaceReturns(space) requirementsFactory.NewSpaceRequirementReturns(spaceReq) }) It("renames a space", func() { originalSpaceName := configRepo.SpaceFields().Name callRenameSpace([]string{"the-old-space-name", "my-new-space"})