示例#1
0
			Expect(runCommand("blahblah")).To(BeFalse())
			Expect(ui.Outputs).To(ContainSubstrings(
				[]string{"Incorrect Usage", "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() {
			testcmd.RunCliCommand("orgs", []string{}, requirementsFactory, updateCommandDependency, true)
示例#2
0
		})

		It("fails when not logged in", func() {
			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.LoginSuccess = true
			requirementsFactory.Organization = org
		})

		Context("shows friendly messaage when no users in ORG_MANAGER role", func() {
			It("shows the special users in the given org", func() {
				userRepo.ListUsersInOrgForRoleStub = func(_ string, roleName string) ([]models.UserFields, error) {
					userFields := map[string][]models.UserFields{
						models.ORG_MANAGER:     []models.UserFields{},
示例#3
0
		ui                  *testterm.FakeUI
		requirementsFactory *testreq.FakeReqFactory
		orgRepo             *test_org.FakeOrganizationRepository
		org                 models.Organization
	)

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

		org = models.Organization{}
		org.Name = "org-to-delete"
		org.Guid = "org-to-delete-guid"
		orgRepo = &test_org.FakeOrganizationRepository{}

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

	runCommand := func(args ...string) bool {
		cmd := NewDeleteOrg(ui, config, orgRepo)
		return testcmd.RunCommand(cmd, args, requirementsFactory)
	}

	It("fails requirements when not logged in", func() {
		Expect(runCommand("some-org-name")).To(BeFalse())
	})
示例#4
0
			Expect(requirementsFactory.UserUsername).To(Equal("username"))
			Expect(requirementsFactory.OrganizationName).To(Equal("org"))
		})
	})

	Context("when logged in", func() {
		BeforeEach(func() {
			requirementsFactory.LoginSuccess = true

			user := models.UserFields{}
			user.Username = "******"
			user.Guid = "some-user-guid"
			org := models.Organization{}
			org.Name = "some-org"
			org.Guid = "some-org-guid"

			requirementsFactory.UserFields = user
			requirementsFactory.Organization = org
		})

		It("unsets a user's org role", func() {
			runCommand("my-username", "my-org", "OrgManager")

			Expect(ui.Outputs).To(ContainSubstrings(
				[]string{"Removing role", "OrgManager", "my-username", "my-org", "my-user"},
				[]string{"OK"},
			))

			Expect(userRepo.UnsetOrgRoleRole).To(Equal(models.ORG_MANAGER))
			Expect(userRepo.UnsetOrgRoleUserGuid).To(Equal("some-user-guid"))
示例#5
0
		serviceRepo.FindServiceOfferingByLabelServiceOffering = service2

		servicePlanRepo.SearchReturns = map[string][]models.ServicePlanFields{
			"service-guid":  {{Name: "service-plan", Guid: "service-plan-guid"}, {Name: "other-plan", Guid: "other-plan-guid"}},
			"service-guid2": {{Name: "service-plan2", Guid: "service-plan2-guid"}},
		}

		servicePlanVisibilityRepo.ListReturns([]models.ServicePlanVisibilityFields{
			{ServicePlanGuid: "service-plan2-guid", OrganizationGuid: "org-guid"},
			{ServicePlanGuid: "service-plan2-guid", OrganizationGuid: "org2-guid"},
		}, nil)

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

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

		orgRepo.Organizations = []models.Organization{
			org1,
			org2,
		}
	})

	Describe("GetBrokerWithSingleService", func() {
		It("Returns a single broker contained in a slice with all dependencies populated", func() {
			brokers, err := actor.GetBrokerWithSingleService("my-service2")
			Expect(err).NotTo(HaveOccurred())
示例#6
0
			requirementsFactory.LoginSuccess = true
		})

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

			It("it updates the organization in the config", func() {
				callTarget([]string{"-o", "my-organization"})

				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() {
示例#7
0
			Expect("some-org").To(Equal(requirementsFactory.OrganizationName))
		})
	})

	It("fails with usage when not invoked with exactly two args", func() {
		runCommand("my-org")
		Expect(ui.FailedWithUsage).To(BeTrue())
	})

	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.FindByNameInOrgSpace = space

			user := models.UserFields{}
			user.Username = "******"
			user2 := models.UserFields{}
			user2.Username = "******"
			user3 := models.UserFields{}
			user3.Username = "******"
			user4 := models.UserFields{}
			user4.Username = "******"
示例#8
0
文件: org_test.go 项目: GABONIA/cli
	It("TestShowOrgRequirements", func() {
		args := []string{"my-org"}

		requirementsFactory := &testreq.FakeReqFactory{LoginSuccess: true}
		callShowOrg(args, requirementsFactory)
		Expect(testcmd.CommandDidPassRequirements).To(BeTrue())

		requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: false}
		callShowOrg(args, requirementsFactory)
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
	})
	It("TestShowOrgFailsWithUsage", func() {

		org := models.Organization{}
		org.Name = "my-org"
		org.Guid = "my-org-guid"
		requirementsFactory := &testreq.FakeReqFactory{Organization: org, LoginSuccess: true}

		args := []string{"my-org"}
		ui := callShowOrg(args, requirementsFactory)
		Expect(ui.FailedWithUsage).To(BeFalse())

		args = []string{}
		ui = callShowOrg(args, requirementsFactory)
		Expect(ui.FailedWithUsage).To(BeTrue())
	})
	It("TestRunWhenOrganizationExists", func() {

		developmentSpaceFields := models.SpaceFields{}
		developmentSpaceFields.Name = "development"
		stagingSpaceFields := models.SpaceFields{}
示例#9
0
		"spaces": [{
		  "metadata": { "guid": "space1-guid" },
		  "entity": { "name": "Space1" }
		}],
		"domains": [{
		  "metadata": { "guid": "domain1-guid" },
		  "entity": { "name": "cfapps.io" }
		}]
	  }
	}]}`},
			})

			testserver, handler, repo := createOrganizationRepo(req)
			defer testserver.Close()
			existingOrg := models.Organization{}
			existingOrg.Guid = "org1-guid"
			existingOrg.Name = "Org1"

			org, apiErr := repo.FindByName("Org1")
			Expect(handler).To(HaveAllRequestsCalled())
			Expect(apiErr).NotTo(HaveOccurred())

			Expect(org.Name).To(Equal(existingOrg.Name))
			Expect(org.Guid).To(Equal(existingOrg.Guid))
			Expect(org.QuotaDefinition.Name).To(Equal("not-your-average-quota"))
			Expect(org.QuotaDefinition.MemoryLimit).To(Equal(int64(128)))
			Expect(len(org.Spaces)).To(Equal(1))
			Expect(org.Spaces[0].Name).To(Equal("Space1"))
			Expect(org.Spaces[0].Guid).To(Equal("space1-guid"))
			Expect(len(org.Domains)).To(Equal(1))
			Expect(org.Domains[0].Name).To(Equal("cfapps.io"))
示例#10
0
		visibility1 models.ServicePlanVisibilityFields
	)

	BeforeEach(func() {
		servicePlanRepo = &testapi.FakeServicePlanRepo{}
		servicePlanVisibilityRepo = &testapi.FakeServicePlanVisibilityRepository{}
		orgRepo = &fake_orgs.FakeOrganizationRepository{}
		planBuilder = &fake_plan_builder.FakePlanBuilder{}
		serviceBuilder = &fake_service_builder.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",
			ServicePlanGuid: "private-service-plan-guid",
			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.FindByNameInOrgError = errors.NewModelNotFoundError("Space", "space-name")
			})

			It("fails and tells the user", func() {
				runCommand("sec group", "org-name", "space-name")

				Expect(fakeSpaceRepo.FindByNameInOrgName).To(Equal("space-name"))
				Expect(fakeSpaceRepo.FindByNameInOrgOrgGuid).To(Equal("org-guid"))
				Expect(ui.Outputs).To(ContainSubstrings(
					[]string{"FAILED"},
					[]string{"Space", "space-name", "not found"},
				))
			})
示例#12
0
		requirementsFactory.LoginSuccess = false
		callOrgUsers(args, requirementsFactory, userRepo)
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())

		requirementsFactory.LoginSuccess = true
		callOrgUsers(args, requirementsFactory, userRepo)
		Expect(testcmd.CommandDidPassRequirements).To(BeTrue())

		Expect("Org1").To(Equal(requirementsFactory.OrganizationName))
	})

	It("TestOrgUsers", func() {
		org := models.Organization{}
		org.Name = "Found Org"
		org.Guid = "found-org-guid"

		userRepo := &testapi.FakeUserRepository{}
		user := models.UserFields{}
		user.Username = "******"
		user2 := models.UserFields{}
		user2.Username = "******"
		user3 := models.UserFields{}
		user3.Username = "******"
		user4 := models.UserFields{}
		user4.Username = "******"
		userRepo.ListUsersByRole = map[string][]models.UserFields{
			models.ORG_MANAGER:     []models.UserFields{user, user2},
			models.BILLING_MANAGER: []models.UserFields{user4},
			models.ORG_AUDITOR:     []models.UserFields{user3},
		}
示例#13
0
		callRenameOrg([]string{"foo"})
		Expect(ui.Outputs).To(ContainSubstrings(
			[]string{"Incorrect Usage", "Requires", "arguments"},
		))
	})

	It("fails requirements when not logged in", func() {
		Expect(callRenameOrg([]string{"my-org", "my-new-org"})).To(BeFalse())
	})

	Context("when logged in and given an org to rename", func() {
		BeforeEach(func() {
			org := models.Organization{}
			org.Name = "the-old-org-name"
			org.Guid = "the-old-org-guid"
			requirementsFactory.Organization = org
			requirementsFactory.LoginSuccess = true
		})

		It("passes requirements", func() {
			Expect(callRenameOrg([]string{"the-old-org-name", "the-new-org-name"})).To(BeTrue())
		})

		It("renames an organization", func() {
			targetedOrgName := configRepo.OrganizationFields().Name
			callRenameOrg([]string{"the-old-org-name", "the-new-org-name"})
			Expect(ui.Outputs).To(ContainSubstrings(
				[]string{"Renaming org", "the-old-org-name", "the-new-org-name", "my-user"},
				[]string{"OK"},
			))
示例#14
0
		requirementsFactory := &testreq.FakeReqFactory{LoginSuccess: true}
		domainRepo := &testapi.FakeDomainRepository{}
		ui := callCreateDomain([]string{""}, requirementsFactory, domainRepo)
		Expect(ui.FailedWithUsage).To(BeTrue())

		ui = callCreateDomain([]string{"org1"}, requirementsFactory, domainRepo)
		Expect(ui.FailedWithUsage).To(BeTrue())

		ui = callCreateDomain([]string{"org1", "example.com"}, requirementsFactory, domainRepo)
		Expect(ui.FailedWithUsage).To(BeFalse())
	})
	It("TestCreateDomain", func() {

		org := models.Organization{}
		org.Name = "myOrg"
		org.Guid = "myOrg-guid"
		requirementsFactory := &testreq.FakeReqFactory{LoginSuccess: true, Organization: org}
		domainRepo := &testapi.FakeDomainRepository{}
		ui := callCreateDomain([]string{"myOrg", "example.com"}, requirementsFactory, domainRepo)

		Expect(domainRepo.CreateDomainName).To(Equal("example.com"))
		Expect(domainRepo.CreateDomainOwningOrgGuid).To(Equal("myOrg-guid"))
		Expect(ui.Outputs).To(ContainSubstrings(
			[]string{"Creating domain", "example.com", "myOrg", "my-user"},
			[]string{"OK"},
		))
	})
})

func callCreateDomain(args []string, requirementsFactory *testreq.FakeReqFactory, domainRepo *testapi.FakeDomainRepository) (fakeUI *testterm.FakeUI) {
	fakeUI = new(testterm.FakeUI)
示例#15
0
	}

	BeforeEach(func() {
		Flags = []string{}
		Config = testconfig.NewRepository()
		ui = &testterm.FakeUI{}
		authRepo = &testapi.FakeAuthenticationRepository{
			AccessToken:  "my_access_token",
			RefreshToken: "my_refresh_token",
			Config:       Config,
		}
		endpointRepo = &testapi.FakeEndpointRepo{}

		org = models.Organization{}
		org.Name = "my-new-org"
		org.Guid = "my-new-org-guid"

		orgRepo = &fake_organizations.FakeOrganizationRepository{}
		orgRepo.ListOrgsReturns([]models.Organization{org}, nil)

		space := models.Space{}
		space.Guid = "my-space-guid"
		space.Name = "my-space"

		spaceRepo = &testapi.FakeSpaceRepository{}
		spaceRepo.ListSpacesStub = listSpacesStub([]models.Space{space})

		authRepo.GetLoginPromptsReturns.Prompts = map[string]core_config.AuthPrompt{
			"username": core_config.AuthPrompt{
				DisplayName: "Username",
				Type:        core_config.AuthPromptTypeText,