Guid: "my-group-guid", Rules: []map[string]interface{}{}, }, } securityGroupRepo.ReadReturns(securityGroup, nil) orgRepo.ListOrgsReturns([]models.Organization{{ OrganizationFields: models.OrganizationFields{ Name: "my-org", Guid: "my-org-guid", }}, }, nil) space := models.Space{SpaceFields: models.SpaceFields{Name: "my-space", Guid: "my-space-guid"}} spaceRepo.FindByNameInOrgReturns(space, nil) }) It("removes the security group when we only pass the security group name (using the targeted org and space)", func() { runCommand("my-group") Expect(ui.Outputs).To(ContainSubstrings( []string{"Unbinding security group", "my-org", "my-space", "my-user"}, []string{"OK"}, )) securityGroupGuid, spaceGuid := secBinder.UnbindSpaceArgsForCall(0) Expect(securityGroupGuid).To(Equal("my-group-guid")) Expect(spaceGuid).To(Equal("my-space-guid")) }) It("removes the security group when we pass the org and space", func() {
requirementsFactory.OrganizationRequirementFails = false flagContext.Parse("the-username", "the-org-name", "the-space-name", "SpaceManager") _, err := cmd.Requirements(requirementsFactory, flagContext) Expect(err).NotTo(HaveOccurred()) org = models.Organization{} org.Guid = "the-org-guid" org.Name = "the-org-name" requirementsFactory.Organization = org }) Context("when the space is not found", func() { BeforeEach(func() { spaceRepo.FindByNameInOrgReturns(models.Space{}, errors.New("space-repo-error")) }) It("doesn't call CC", func() { Expect(userRepo.SetSpaceRoleByGuidCallCount()).To(BeZero()) Expect(userRepo.SetSpaceRoleByUsernameCallCount()).To(BeZero()) }) It("panics and prints a failure message", func() { Expect(func() { cmd.Execute(flagContext) }).To(Panic()) Expect(ui.Outputs).To(BeInDisplayOrder( []string{"FAILED"}, []string{"space-repo-error"}, )) }) })
Expect(fakeOrgRepo.FindByNameArgsForCall(0)).To(Equal("org")) Expect(ui.Outputs).To(ContainSubstrings( []string{"FAILED"}, []string{"Org", "org", "not found"}, )) }) }) Context("when the space does not exist", func() { BeforeEach(func() { org := models.Organization{} org.Name = "org-name" org.Guid = "org-guid" fakeOrgRepo.ListOrgsReturns([]models.Organization{org}, nil) fakeOrgRepo.FindByNameReturns(org, nil) fakeSpaceRepo.FindByNameInOrgReturns(models.Space{}, errors.NewModelNotFoundError("Space", "space-name")) }) It("fails and tells the user", func() { runCommand("sec group", "org-name", "space-name") name, orgGUID := fakeSpaceRepo.FindByNameInOrgArgsForCall(0) Expect(name).To(Equal("space-name")) Expect(orgGUID).To(Equal("org-guid")) Expect(ui.Outputs).To(ContainSubstrings( []string{"FAILED"}, []string{"Space", "space-name", "not found"}, )) }) })