It("fails when an org is not targeted", func() { requirementsFactory.LoginSuccess = true runCommand() Expect(testcmd.CommandDidPassRequirements).To(BeFalse()) }) }) Context("when logged in and an org is targeted", func() { BeforeEach(func() { space := models.Space{} space.Name = "space1" space2 := models.Space{} space2.Name = "space2" space3 := models.Space{} space3.Name = "space3" spaceRepo.Spaces = []models.Space{space, space2, space3} requirementsFactory.LoginSuccess = true requirementsFactory.TargetedOrgSuccess = true }) It("lists all of the spaces", func() { runCommand() Expect(ui.Outputs).To(ContainSubstrings( []string{"Getting spaces in org", "my-org", "my-user"}, []string{"space1"}, []string{"space2"}, []string{"space3"}, )) })
models.SpaceQuota{ Name: "quota-name", Guid: "quota-guid", MemoryLimit: 1024, InstanceMemoryLimit: 512, RoutesLimit: 111, ServicesLimit: 222, NonBasicServicesAllowed: true, OrgGuid: "my-org-guid", }, nil) spaceRepo.Spaces = []models.Space{ models.Space{ SpaceFields: models.SpaceFields{ Name: "my-space", Guid: "my-space-guid", }, SpaceQuotaGuid: "", }, } }) Context("when the space quota was not previously assigned to a space", func() { It("associates the provided space with the provided space quota", func() { spaceGuid, quotaGuid := quotaRepo.AssociateSpaceWithQuotaArgsForCall(0) Expect(spaceGuid).To(Equal("my-space-guid")) Expect(quotaGuid).To(Equal("quota-guid")) Expect(ui.Outputs).To(ContainSubstrings( []string{"Assigning space quota", "to space", "my-user"}, []string{"OK"},
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() { spaceRepo.Spaces = []models.Space{ { SpaceFields: models.SpaceFields{ Name: "space-name", Guid: "model-space-guid", }, }, } 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"}, ))
org1.Name = "some-org" org2 = models.Organization{} org2.Guid = "my-new-org-guid" org2.Name = "my-new-org" space1 := models.Space{} space1.Guid = "my-space-guid" space1.Name = "my-space" space2 = models.Space{} space2.Guid = "some-space-guid" space2.Name = "some-space" orgRepo.ListOrgsReturns([]models.Organization{org1, org2}, nil) spaceRepo.Spaces = []models.Space{space1, space2} }) It("lets the user select an org and space by number", func() { orgRepo.FindByNameReturns(org2, nil) OUT_OF_RANGE_CHOICE := "3" ui.Inputs = []string{"api.example.com", "*****@*****.**", "password", OUT_OF_RANGE_CHOICE, "2", OUT_OF_RANGE_CHOICE, "1"} l := NewLogin(ui, Config, authRepo, endpointRepo, orgRepo, spaceRepo) testcmd.RunCommand(l, Flags, nil) Expect(ui.Outputs).To(ContainSubstrings( []string{"Select an org"}, []string{"1. some-org"}, []string{"2. my-new-org"}, []string{"Select a space"},
requirementsFactory.TargetedOrgSuccess = true }) It("unassigns a quota from a space", func() { space := models.Space{ SpaceFields: models.SpaceFields{ Name: "my-space", Guid: "my-space-guid", }, } quota := models.SpaceQuota{Name: "my-quota", Guid: "my-quota-guid"} quotaRepo.FindByNameReturns(quota, nil) spaceRepo.FindByNameName = space.Name spaceRepo.Spaces = []models.Space{space} runCommand("my-space", "my-quota") Expect(ui.Outputs).To(ContainSubstrings( []string{"Unassigning space quota", "my-quota", "my-space", "my-user"}, []string{"OK"}, )) Expect(quotaRepo.FindByNameArgsForCall(0)).To(Equal("my-quota")) spaceGuid, quotaGuid := quotaRepo.UnassignQuotaFromSpaceArgsForCall(0) Expect(spaceGuid).To(Equal("my-space-guid")) Expect(quotaGuid).To(Equal("my-quota-guid")) }) }) })