예제 #1
0
					Expect(actualRequirements).To(ContainElement(userRequirement))
				})
			})
		})
	})

	Describe("Execute", func() {
		var err error

		BeforeEach(func() {
			flagContext.Parse("the-user-name", "the-org-name", "OrgManager")
			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 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())
예제 #2
0
	"code.cloudfoundry.org/cli/cf/models"
	. "code.cloudfoundry.org/cli/cf/requirements"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("OrganizationRequirement", func() {
	var orgRepo *organizationsfakes.FakeOrganizationRepository
	BeforeEach(func() {
		orgRepo = new(organizationsfakes.FakeOrganizationRepository)
	})

	Context("when an org with the given name exists", func() {
		It("succeeds", func() {
			org := models.Organization{}
			org.Name = "my-org-name"
			org.GUID = "my-org-guid"
			orgReq := NewOrganizationRequirement("my-org-name", orgRepo)

			orgRepo.ListOrgsReturns([]models.Organization{org}, nil)
			orgRepo.FindByNameReturns(org, nil)

			err := orgReq.Execute()
			Expect(err).NotTo(HaveOccurred())
			Expect(orgRepo.FindByNameArgsForCall(0)).To(Equal("my-org-name"))
			Expect(orgReq.GetOrganization()).To(Equal(org))
		})
	})

	It("fails when the org with the given name does not exist", func() {
		orgError := errors.New("not found")
예제 #3
0
		})

		It("fails when not logged in", func() {
			requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
			Expect(runCommand("say-hello-to-my-little-org")).To(BeFalse())
		})
	})

	Context("when logged in and given an org with no users in a particular role", func() {
		var (
			user1, user2 models.UserFields
		)

		BeforeEach(func() {
			org := models.Organization{}
			org.Name = "the-org"
			org.GUID = "the-org-guid"

			user1 = models.UserFields{}
			user1.Username = "******"
			user2 = models.UserFields{}
			user2.Username = "******"

			requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
			organizationReq := new(requirementsfakes.FakeOrganizationRequirement)
			organizationReq.GetOrganizationReturns(org)
			requirementsFactory.NewOrganizationRequirementReturns(organizationReq)
		})

		Context("shows friendly messaage when no users in ORG_MANAGER role", func() {
			It("shows the special users in the given org", func() {
예제 #4
0
		BeforeEach(func() {
			requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
		})

		var expectOrgToBeCleared = func() {
			Expect(config.OrganizationFields()).To(Equal(models.OrganizationFields{}))
		}

		var expectSpaceToBeCleared = func() {
			Expect(config.SpaceFields()).To(Equal(models.SpaceFields{}))
		}

		Context("there are no errors", func() {
			BeforeEach(func() {
				org := models.Organization{}
				org.Name = "my-organization"
				org.GUID = "my-organization-guid"

				orgRepo.ListOrgsReturns([]models.Organization{org}, nil)
				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"))
예제 #5
0
			})
			requirementsFactory.NewOrganizationRequirementReturns(fakeOrgRequirement)
			Expect(runCommand("my-org", "example.com")).To(BeTrue())
			Expect(ui.Outputs()).To(ContainSubstrings([]string{"my-org"}))
		})

		It("fails when not logged in", func() {
			requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})

			Expect(runCommand("my-org", "example.com")).To(BeFalse())
		})
	})

	It("creates a domain", func() {
		org := models.Organization{}
		org.Name = "myOrg"
		org.GUID = "myOrg-guid"
		fakeOrgRequirement := new(requirementsfakes.FakeOrganizationRequirement)
		fakeOrgRequirement.GetOrganizationReturns(org)
		requirementsFactory.NewOrganizationRequirementReturns(fakeOrgRequirement)
		requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
		runCommand("myOrg", "example.com")

		domainName, domainOwningOrgGUID := domainRepo.CreateArgsForCall(0)
		Expect(domainName).To(Equal("example.com"))
		Expect(domainOwningOrgGUID).To(Equal("myOrg-guid"))
		Expect(ui.Outputs()).To(ContainSubstrings(
			[]string{"Creating domain", "example.com", "myOrg", "my-user"},
			[]string{"OK"},
		))
	})
예제 #6
0
		})
	})

	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{}
예제 #7
0
	updateCommandDependency := func(pluginCall bool) {
		deps.UI = ui
		deps.RepoLocator = deps.RepoLocator.SetOrganizationRepository(orgRepo)
		deps.Config = config
		commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("delete-org").SetDependency(deps, pluginCall))
	}

	BeforeEach(func() {
		ui = &testterm.FakeUI{
			Inputs: []string{"y"},
		}
		config = testconfig.NewRepositoryWithDefaults()
		requirementsFactory = new(requirementsfakes.FakeFactory)

		org = models.Organization{}
		org.Name = "org-to-delete"
		org.GUID = "org-to-delete-guid"
		orgRepo = new(organizationsfakes.FakeOrganizationRepository)

		orgRepo.ListOrgsReturns([]models.Organization{org}, nil)
		orgRepo.FindByNameReturns(org, nil)
	})

	runCommand := func(args ...string) bool {
		return testcmd.RunCLICommand("delete-org", args, requirementsFactory, updateCommandDependency, false, ui)
	}

	It("fails requirements when not logged in", func() {
		requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
		Expect(runCommand("some-org-name")).To(BeFalse())
	})
예제 #8
0
			It("fails and tells the user", func() {
				runCommand("sec group", "org", "space")

				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"},
예제 #9
0
파일: orgs_test.go 프로젝트: fujitsu-cf/cli
				err = testcmd.RunRequirements(reqs)
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("Incorrect Usage"))
				Expect(err.Error()).To(ContainSubstring("No argument required"))
			})
		})
	})

	Describe("when invoked by a plugin", func() {
		var (
			pluginOrgsModel []plugin_models.GetOrgs_Model
		)

		BeforeEach(func() {
			org1 := models.Organization{}
			org1.Name = "Organization-1"
			org1.GUID = "org-1-guid"

			org2 := models.Organization{}
			org2.Name = "Organization-2"

			org3 := models.Organization{}
			org3.Name = "Organization-3"

			orgRepo.ListOrgsReturns([]models.Organization{org1, org2, org3}, nil)

			pluginOrgsModel = []plugin_models.GetOrgs_Model{}
			deps.PluginModels.Organizations = &pluginOrgsModel
		})

		It("populates the plugin models upon execution", func() {
예제 #10
0
		orgRepo = new(organizationsfakes.FakeOrganizationRepository)
		brokerBuilder = new(brokerbuilderfakes.FakeBrokerBuilder)
		serviceBuilder = new(servicebuilderfakes.FakeServiceBuilder)

		actor = actors.NewServiceHandler(orgRepo, brokerBuilder, serviceBuilder)

		serviceBroker1 = models.ServiceBroker{GUID: "my-service-broker-guid1", Name: "my-service-broker1"}

		service1 = models.ServiceOffering{ServiceOfferingFields: models.ServiceOfferingFields{
			Label:      "my-service1",
			GUID:       "service-guid1",
			BrokerGUID: "my-service-broker-guid1"},
		}

		org1 := models.Organization{}
		org1.Name = "org1"
		org1.GUID = "org-guid"

		org2 := models.Organization{}
		org2.Name = "org2"
		org2.GUID = "org2-guid"
	})

	Describe("FilterBrokers", func() {
		Context("when no flags are passed", func() {
			It("returns all brokers", func() {
				returnedBrokers := []models.ServiceBroker{serviceBroker1}
				brokerBuilder.GetAllServiceBrokersReturns(returnedBrokers, nil)

				brokers, err := actor.FilterBrokers("", "", "")
				Expect(err).NotTo(HaveOccurred())
예제 #11
0
		deps.UI = ui
		deps.Config = configRepo
		deps.RepoLocator = deps.RepoLocator.SetSpaceQuotaRepository(quotaRepo)
		deps.RepoLocator = deps.RepoLocator.SetOrganizationRepository(orgRepo)
		commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("delete-space-quota").SetDependency(deps, pluginCall))
	}

	BeforeEach(func() {
		ui = &testterm.FakeUI{}
		quotaRepo = new(spacequotasfakes.FakeSpaceQuotaRepository)
		orgRepo = new(organizationsfakes.FakeOrganizationRepository)
		configRepo = testconfig.NewRepositoryWithDefaults()
		requirementsFactory = new(requirementsfakes.FakeFactory)

		org := models.Organization{}
		org.Name = "my-org"
		org.GUID = "my-org-guid"
		orgRepo.ListOrgsReturns([]models.Organization{org}, nil)
		orgRepo.FindByNameReturns(org, nil)
	})

	runCommand := func(args ...string) bool {
		return testcmd.RunCLICommand("delete-space-quota", args, requirementsFactory, updateCommandDependency, false, ui)
	}

	Context("when the user is not logged in", func() {
		BeforeEach(func() {
			requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
		})

		It("fails requirements", func() {
예제 #12
0
	BeforeEach(func() {
		Flags = []string{}
		Config = testconfig.NewRepository()
		ui = &testterm.FakeUI{}
		authRepo = new(authenticationfakes.FakeRepository)
		authRepo.AuthenticateStub = func(credentials map[string]string) error {
			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",
예제 #13
0
		org2 models.Organization

		visibility1 models.ServicePlanVisibilityFields
	)

	BeforeEach(func() {
		servicePlanRepo = new(apifakes.OldFakeServicePlanRepo)
		servicePlanVisibilityRepo = new(apifakes.FakeServicePlanVisibilityRepository)
		orgRepo = new(organizationsfakes.FakeOrganizationRepository)
		planBuilder = new(planbuilderfakes.FakePlanBuilder)
		serviceBuilder = new(servicebuilderfakes.FakeServiceBuilder)

		actor = actors.NewServicePlanHandler(servicePlanRepo, servicePlanVisibilityRepo, orgRepo, planBuilder, serviceBuilder)

		org1 = models.Organization{}
		org1.Name = "org-1"
		org1.GUID = "org-1-guid"

		org2 = models.Organization{}
		org2.Name = "org-2"
		org2.GUID = "org-2-guid"

		orgRepo.FindByNameReturns(org1, nil)

		publicServicePlanVisibilityFields = models.ServicePlanVisibilityFields{
			GUID:            "public-service-plan-visibility-guid",
			ServicePlanGUID: "public-service-plan-guid",
		}

		privateServicePlanVisibilityFields = models.ServicePlanVisibilityFields{
			GUID:            "private-service-plan-visibility-guid",