Пример #1
0
			flagContext.Parse("the-user-name", "the-org-name", "the-space-name", "SpaceManager")
			cmd.Requirements(factory, flagContext)

			org = models.Organization{}
			org.GUID = "the-org-guid"
			org.Name = "the-org-name"
			organizationRequirement.GetOrganizationReturns(org)
		})

		JustBeforeEach(func() {
			err = cmd.Execute(flagContext)
		})

		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.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() {
Пример #2
0
				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"},
				))
			})
		})
Пример #3
0
		))
	})

	Context("when logged in and given some users in the org and space", func() {
		BeforeEach(func() {
			requirementsFactory.LoginSuccess = true

			org := models.Organization{}
			org.Name = "Org1"
			org.GUID = "org1-guid"
			space := models.Space{}
			space.Name = "Space1"
			space.GUID = "space1-guid"

			requirementsFactory.Organization = org
			spaceRepo.FindByNameInOrgReturns(space, nil)

			user := models.UserFields{}
			user.Username = "******"
			user2 := models.UserFields{}
			user2.Username = "******"
			user3 := models.UserFields{}
			user3.Username = "******"
			user4 := models.UserFields{}
			user4.Username = "******"
			userRepo.ListUsersInSpaceForRoleStub = func(_ string, roleName models.Role) ([]models.UserFields, error) {
				userFields := map[models.Role][]models.UserFields{
					models.RoleSpaceManager:   {user, user2},
					models.RoleSpaceDeveloper: {user4},
					models.RoleSpaceAuditor:   {user3},
				}[roleName]
Пример #4
0
			Expect(runCommand("my-org", "my-space")).To(BeFalse())
		})

		It("succeeds when logged in", func() {
			requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
			organizationReq := new(requirementsfakes.FakeOrganizationRequirement)
			organizationReq.GetOrganizationReturns(
				models.Organization{
					OrganizationFields: models.OrganizationFields{
						Name: "some-org",
					},
				},
			)
			spaceRepo.FindByNameInOrgReturns(
				models.Space{
					SpaceFields: models.SpaceFields{
						Name: "whatever-space",
					},
				}, nil)
			requirementsFactory.NewOrganizationRequirementReturns(organizationReq)
			passed := runCommand("some-org", "whatever-space")

			Expect(passed).To(BeTrue())
			Expect(ui.Outputs()).To(ContainSubstrings([]string{"Getting users in org some-org / space whatever-space as my-user"}))
		})
	})

	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"},
		))