コード例 #1
0
ファイル: login_test.go プロジェクト: normalnorman/cli
func setUpLoginTestContext() (c *LoginTestContext) {
	c = new(LoginTestContext)
	c.Config = testconfig.NewRepository()

	c.ui = &testterm.FakeUI{}

	c.authRepo = &testapi.FakeAuthenticationRepository{
		AccessToken:  "my_access_token",
		RefreshToken: "my_refresh_token",
		Config:       c.Config,
	}
	c.endpointRepo = &testapi.FakeEndpointRepo{Config: c.Config}

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

	c.orgRepo = &testapi.FakeOrgRepository{
		Organizations: []models.Organization{org},
	}

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

	c.spaceRepo = &testapi.FakeSpaceRepository{
		Spaces: []models.Space{space},
	}

	return
}
コード例 #2
0
ファイル: set_quota_test.go プロジェクト: nota-ja/cli
	Context("when logged in", func() {
		BeforeEach(func() {
			requirementsFactory.LoginSuccess = true
		})

		It("passes requirements when provided two args", func() {
			runCommand("my-org", "my-quota")
			Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
			Expect(requirementsFactory.OrganizationName).To(Equal("my-org"))
		})

		It("assigns a quota to an org", func() {
			org := models.Organization{}
			org.Name = "my-org"
			org.Guid = "my-org-guid"

			quota := models.QuotaFields{Name: "my-quota", Guid: "my-quota-guid"}

			quotaRepo.FindByNameReturns.Quota = quota
			requirementsFactory.Organization = org

			runCommand("my-org", "my-quota")

			testassert.SliceContains(ui.Outputs, testassert.Lines{
				{"Setting quota", "my-quota", "my-org", "my-user"},
				{"OK"},
			})

			Expect(quotaRepo.FindByNameCalledWith.Name).To(Equal("my-quota"))
			Expect(quotaRepo.AssignQuotaToOrgCalledWith.OrgGuid).To(Equal("my-org-guid"))
コード例 #3
0
ファイル: create_domain_test.go プロジェクト: nota-ja/cli
		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"))
		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"Creating domain", "example.com", "myOrg", "my-user"},
			{"OK"},
		})
	})
})

func callCreateDomain(args []string, requirementsFactory *testreq.FakeReqFactory, domainRepo *testapi.FakeDomainRepository) (fakeUI *testterm.FakeUI) {
	fakeUI = new(testterm.FakeUI)
コード例 #4
0
ファイル: organizations_test.go プロジェクト: julz/cli
		"spaces": [{
		  "metadata": { "guid": "space1-guid" },
		  "entity": { "name": "Space1" }
		}],
		"domains": [{
		  "metadata": { "guid": "domain1-guid" },
		  "entity": { "name": "cfapps.io" }
		}]
	  }
	}]}`},
		})

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

		org, apiErr := repo.FindByName("Org1")
		Expect(handler).To(testnet.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(uint64(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"))
コード例 #5
0
ファイル: target_test.go プロジェクト: jibin-tomy/cli
		BeforeEach(func() {
			reqFactory.LoginSuccess = true
		})

		It("passes requirements when targeting a space or org", func() {
			callTarget([]string{"-s", "i-love-space"}, reqFactory, config, orgRepo, spaceRepo)
			Expect(testcmd.CommandDidPassRequirements).To(BeTrue())

			callTarget([]string{"-o", "orgs-are-delightful"}, reqFactory, config, orgRepo, spaceRepo)
			Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
		})

		It("TestTargetOrganizationWhenUserHasAccess", func() {
			org := models.Organization{}
			org.Name = "my-organization"
			org.Guid = "my-organization-guid"

			orgRepo.Organizations = []models.Organization{org}
			orgRepo.FindByNameOrganization = org

			ui := callTarget([]string{"-o", "my-organization"}, reqFactory, config, orgRepo, spaceRepo)

			Expect(orgRepo.FindByNameName).To(Equal("my-organization"))
			Expect(ui.ShowConfigurationCalled).To(BeTrue())

			Expect(config.OrganizationFields().Guid).To(Equal("my-organization-guid"))
		})

		It("TestTargetOrganizationWhenUserDoesNotHaveAccess", func() {
			orgs := []models.Organization{}
			orgRepo.Organizations = orgs
コード例 #6
0
ファイル: login_test.go プロジェクト: juggernaut/cli
	)

	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 = &testapi.FakeOrgRepository{
			Organizations:          []models.Organization{org},
			FindByNameOrganization: models.Organization{},
		}

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

		spaceRepo = &testapi.FakeSpaceRepository{
			Spaces: []models.Space{space},
		}

		authRepo.GetLoginPromptsReturns.Prompts = map[string]configuration.AuthPrompt{
コード例 #7
0
ファイル: unset_space_role_test.go プロジェクト: nota-ja/cli
		requirementsFactory.LoginSuccess = true
		callUnsetSpaceRole(args, spaceRepo, userRepo, requirementsFactory)
		Expect(testcmd.CommandDidPassRequirements).To(BeTrue())

		Expect(requirementsFactory.UserUsername).To(Equal("username"))
		Expect(requirementsFactory.OrganizationName).To(Equal("org"))
	})

	It("TestUnsetSpaceRole", func() {
		user := models.UserFields{}
		user.Username = "******"
		user.Guid = "some-user-guid"
		org := models.Organization{}
		org.Name = "some-org"
		org.Guid = "some-org-guid"

		requirementsFactory, spaceRepo, userRepo := getUnsetSpaceRoleDeps()
		requirementsFactory.LoginSuccess = true
		requirementsFactory.UserFields = user
		requirementsFactory.Organization = org
		spaceRepo.FindByNameInOrgSpace = models.Space{}
		spaceRepo.FindByNameInOrgSpace.Name = "some-space"
		spaceRepo.FindByNameInOrgSpace.Guid = "some-space-guid"

		args := []string{"my-username", "my-org", "my-space", "SpaceManager"}

		ui := callUnsetSpaceRole(args, spaceRepo, userRepo, requirementsFactory)

		Expect(spaceRepo.FindByNameInOrgName).To(Equal("my-space"))
		Expect(spaceRepo.FindByNameInOrgOrgGuid).To(Equal("some-org-guid"))
コード例 #8
0
ファイル: delete_org_test.go プロジェクト: nota-ja/cli
		config              configuration.ReadWriter
		ui                  *testterm.FakeUI
		requirementsFactory *testreq.FakeReqFactory
		orgRepo             *testapi.FakeOrgRepository
	)

	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 = &testapi.FakeOrgRepository{Organizations: []models.Organization{org}}
	})

	runCommand := func(args ...string) {
		cmd := NewDeleteOrg(ui, config, orgRepo)
		testcmd.RunCommand(cmd, testcmd.NewContext("delete-org", args), requirementsFactory)
	}

	It("fails requirements when not logged in", func() {
		runCommand("some-org-name")

		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
	})

	It("fails with usage if no arguments are given", func() {
コード例 #9
0
ファイル: rename_org_test.go プロジェクト: knolleary/cli
		Expect(ui.FailedWithUsage).To(BeTrue())

		callRenameOrg([]string{"foo"})
		Expect(ui.FailedWithUsage).To(BeTrue())
	})

	It("fails requirements when not logged in", func() {
		callRenameOrg([]string{"my-org", "my-new-org"})
		Expect(testcmd.CommandDidPassRequirements).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() {
			callRenameOrg([]string{"the-old-org-name", "the-new-org-name"})
			Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
		})

		It("renames an organization", func() {
			targetedOrgName := configRepo.OrganizationFields().Name
			callRenameOrg([]string{"the-old-org-name", "the-new-org-name"})
			testassert.SliceContains(ui.Outputs, testassert.Lines{
				{"Renaming org", "the-old-org-name", "the-new-org-name", "my-user"},
				{"OK"},
コード例 #10
0
ファイル: org_users_test.go プロジェクト: nota-ja/cli
		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},
		}
コード例 #11
0
ファイル: space_users_test.go プロジェクト: nota-ja/cli
		requirementsFactory.LoginSuccess = false
		callSpaceUsers(args, requirementsFactory, spaceRepo, userRepo)
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())

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

		Expect("my-org").To(Equal(requirementsFactory.OrganizationName))
	})
	It("TestSpaceUsers", func() {

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

		requirementsFactory := &testreq.FakeReqFactory{LoginSuccess: true, Organization: org}
		spaceRepo := &testapi.FakeSpaceRepository{FindByNameInOrgSpace: space}
		userRepo := &testapi.FakeUserRepository{}

		user := models.UserFields{}
		user.Username = "******"
		user2 := models.UserFields{}
		user2.Username = "******"
		user3 := models.UserFields{}
		user3.Username = "******"
		user4 := models.UserFields{}