Ejemplo n.º 1
0
			})

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

		Context("when the space is found", func() {
			BeforeEach(func() {
				space := models.Space{}
				space.Guid = "the-space-guid"
				space.Name = "the-space-name"
				space.Organization = org.OrganizationFields
				spaceRepo.FindByNameInOrgReturns(space, nil)
			})

			Context("when the UserRequirement returns a user with a GUID", func() {
				BeforeEach(func() {
					userFields := models.UserFields{Guid: "the-user-guid", Username: "******"}
					requirementsFactory.UserFields = userFields
				})

				It("tells the user it is assigning the role", func() {
					cmd.Execute(flagContext)
					Expect(ui.Outputs).To(ContainSubstrings(
						[]string{"Assigning role", "SpaceManager", "the-username", "the-org", "the-username"},
						[]string{"OK"},
Ejemplo n.º 2
0
		requirementsFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true}
		callSpaces([]string{}, requirementsFactory, config, spaceRepo)
		Expect(testcmd.CommandDidPassRequirements).To(BeTrue())

		requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: false}
		callSpaces([]string{}, requirementsFactory, config, spaceRepo)
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())

		requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: false, TargetedOrgSuccess: true}
		callSpaces([]string{}, requirementsFactory, config, spaceRepo)
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
	})

	It("TestListingSpaces", func() {
		space := models.Space{}
		space.Name = "space1"
		space2 := models.Space{}
		space2.Name = "space2"
		space3 := models.Space{}
		space3.Name = "space3"
		spaceRepo := &testapi.FakeSpaceRepository{
			Spaces: []models.Space{space, space2, space3},
		}

		config := testconfig.NewRepositoryWithDefaults()
		requirementsFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true}

		ui := callSpaces([]string{}, requirementsFactory, config, spaceRepo)

		Expect(ui.Outputs).To(ContainSubstrings(
			[]string{"Getting spaces in org", "my-org", "my-user"},
Ejemplo n.º 3
0
			domain := models.DomainFields{}
			domain.Name = "domain1"
			domain.Guid = "domain1-guid"
			domains := []models.DomainFields{domain}

			serviceInstance := models.ServiceInstanceFields{}
			serviceInstance.Name = "service1"
			serviceInstance.Guid = "service1-guid"
			services := []models.ServiceInstanceFields{serviceInstance}

			securityGroup1 := models.SecurityGroupFields{Name: "Nacho Security"}
			securityGroup2 := models.SecurityGroupFields{Name: "Nacho Prime"}
			securityGroups := []models.SecurityGroupFields{securityGroup1, securityGroup2}

			space := models.Space{}
			space.Name = "whose-space-is-it-anyway"
			space.Organization = org
			space.Applications = apps
			space.Domains = domains
			space.ServiceInstances = services
			space.SecurityGroups = securityGroups
			space.SpaceQuotaGuid = "runaway-guid"

			quota := models.SpaceQuota{}
			quota.Guid = "runaway-guid"
			quota.Name = "runaway"
			quota.MemoryLimit = 102400
			quota.InstanceMemoryLimit = -1
			quota.RoutesLimit = 111
			quota.ServicesLimit = 222
			quota.NonBasicServicesAllowed = false
Ejemplo n.º 4
0
				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"))
			})

			It("updates the space in the config", func() {
				space := models.Space{}
				space.Name = "my-space"
				space.GUID = "my-space-guid"

				spaceRepo.FindByNameReturns(space, nil)

				callTarget([]string{"-s", "my-space"})

				Expect(spaceRepo.FindByNameCallCount()).To(Equal(1))
				Expect(spaceRepo.FindByNameArgsForCall(0)).To(Equal("my-space"))
				Expect(config.SpaceFields().GUID).To(Equal("my-space-guid"))
				Expect(ui.ShowConfigurationCalled).To(BeTrue())
			})

			It("updates both the organization and the space in the config", func() {
				space := models.Space{}
				space.Name = "my-space"
Ejemplo n.º 5
0
			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(apifakes.FakeSpaceRepository)
		spaceRepo.ListSpacesStub = listSpacesStub([]models.Space{space})

		authRepo.GetLoginPromptsAndSaveUAAServerURLReturns(map[string]coreconfig.AuthPrompt{
			"username": {
				DisplayName: "Username",
				Type:        coreconfig.AuthPromptTypeText,
			},
			"password": {
				DisplayName: "Password",
				Type:        coreconfig.AuthPromptTypePassword,
			},
		}, nil)
	})
Ejemplo n.º 6
0
			callRenameSpace([]string{"my-space", "my-new-space"})
			Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
		})
	})

	Describe("when the user provides fewer than two args", func() {
		It("fails with usage", func() {
			callRenameSpace([]string{"foo"})
			Expect(ui.FailedWithUsage).To(BeTrue())
		})
	})

	Describe("when the user is logged in and has provided an old and new space name", func() {
		BeforeEach(func() {
			space := models.Space{}
			space.Name = "the-old-space-name"
			space.Guid = "the-old-space-guid"
			requirementsFactory.Space = space
		})

		It("renames a space", func() {
			originalSpaceName := configRepo.SpaceFields().Name
			callRenameSpace([]string{"the-old-space-name", "my-new-space"})

			Expect(ui.Outputs).To(ContainSubstrings(
				[]string{"Renaming space", "the-old-space-name", "my-new-space", "my-org", "my-user"},
				[]string{"OK"},
			))

			Expect(spaceRepo.RenameSpaceGuid).To(Equal("the-old-space-guid"))
			Expect(spaceRepo.RenameNewName).To(Equal("my-new-space"))
Ejemplo n.º 7
0
			Ui:          ui,
			Config:      configRepo,
			RepoLocator: repoLocator,
		}

		cmd = route.CreateRoute{}
		cmd.SetDependency(deps, false)

		flagContext = flags.NewFlagContext(cmd.MetaData().Flags)

		factory = &fakerequirements.FakeFactory{}

		spaceRequirement = &fakerequirements.FakeSpaceRequirement{}
		space := models.Space{}
		space.Guid = "space-guid"
		space.Name = "space-name"
		spaceRequirement.GetSpaceReturns(space)
		factory.NewSpaceRequirementReturns(spaceRequirement)

		domainRequirement = &fakerequirements.FakeDomainRequirement{}
		domainRequirement.GetDomainReturns(models.DomainFields{
			Guid: "domain-guid",
			Name: "domain-name",
		})
		factory.NewDomainRequirementReturns(domainRequirement)

		minAPIVersionRequirement = &passingRequirement{}
		factory.NewMinAPIVersionRequirementReturns(minAPIVersionRequirement)
	})

	Describe("Requirements", func() {
Ejemplo n.º 8
0
import (
	"github.com/cloudfoundry/cli/cf/models"
	. "github.com/cloudfoundry/cli/cf/requirements"
	testapi "github.com/cloudfoundry/cli/testhelpers/api"
	testassert "github.com/cloudfoundry/cli/testhelpers/assert"
	testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Testing with ginkgo", func() {
	It("TestSpaceReqExecute", func() {

		space := models.Space{}
		space.Name = "awesome-sauce-space"
		space.Guid = "my-space-guid"
		spaceRepo := &testapi.FakeSpaceRepository{Spaces: []models.Space{space}}
		ui := new(testterm.FakeUI)

		spaceReq := NewSpaceRequirement("awesome-sauce-space", ui, spaceRepo)
		success := spaceReq.Execute()

		Expect(success).To(BeTrue())
		Expect(spaceRepo.FindByNameName).To(Equal("awesome-sauce-space"))
		Expect(spaceReq.GetSpace()).To(Equal(space))
	})

	It("TestSpaceReqExecuteWhenSpaceNotFound", func() {

		spaceRepo := &testapi.FakeSpaceRepository{FindByNameNotFound: true}
Ejemplo n.º 9
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.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 string) ([]models.UserFields, error) {
				userFields := map[string][]models.UserFields{
Ejemplo n.º 10
0
	It("unsets the user's space role", 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

		space := models.Space{}
		space.Name = "some-space"
		space.Guid = "some-space-guid"
		spaceRepo.FindByNameInOrgReturns(space, nil)

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

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

		actualSpaceName, actualOrgGUID := spaceRepo.FindByNameInOrgArgsForCall(0)
		Expect(actualSpaceName).To(Equal("my-space"))
		Expect(actualOrgGUID).To(Equal("some-org-guid"))

		Expect(ui.Outputs).To(ContainSubstrings(
			[]string{"Removing role", "SpaceManager", "some-user", "some-org", "some-space", "my-user"},
			[]string{"OK"},
		))
Ejemplo n.º 11
0
	})

	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 = "******"
			userRepo.ListUsersByRole = map[string][]models.UserFields{
				models.SPACE_MANAGER:   []models.UserFields{user, user2},
Ejemplo n.º 12
0
		ui                   *testterm.FakeUI
		appSecurityGroupRepo *testapi.FakeSecurityGroup
		requirementsFactory  *testreq.FakeReqFactory
		spaceRepo            *testapi.FakeSpaceRepository
		configRepo           configuration.ReadWriter
	)

	BeforeEach(func() {
		ui = &testterm.FakeUI{}
		requirementsFactory = &testreq.FakeReqFactory{}
		appSecurityGroupRepo = &testapi.FakeSecurityGroup{}
		configRepo = testconfig.NewRepositoryWithDefaults()

		space := models.Space{}
		space.Guid = "space-guid-1"
		space.Name = "space-1"
		space2 := models.Space{}
		space2.Guid = "space-guid-2"
		space2.Name = "space-2"

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

	runCommand := func(args ...string) {
		cmd := NewCreateSecurityGroup(ui, configRepo, appSecurityGroupRepo, spaceRepo)
		testcmd.RunCommand(cmd, args, requirementsFactory)
	}

	Describe("requirements", func() {
Ejemplo n.º 13
0
			org.Guid = "my-organization-guid"

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

			callTarget([]string{"-o", "my-organization"})

			Expect(orgRepo.FindByNameName).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() {
			space := models.Space{}
			space.Name = "my-space"
			space.Guid = "my-space-guid"

			spaceRepo.Spaces = []models.Space{space}
			spaceRepo.FindByNameSpace = space

			callTarget([]string{"-s", "my-space"})

			Expect(spaceRepo.FindByNameName).To(Equal("my-space"))
			Expect(config.SpaceFields().Guid).To(Equal("my-space-guid"))
			Expect(ui.ShowConfigurationCalled).To(BeTrue())
		})

		It("updates both the organization and the space in the config", func() {
			org := models.Organization{}
			org.Name = "my-organization"
Ejemplo n.º 14
0
		app.Name = "app1"
		app.Guid = "app1-guid"
		apps := []models.ApplicationFields{app}

		domain := models.DomainFields{}
		domain.Name = "domain1"
		domain.Guid = "domain1-guid"
		domains := []models.DomainFields{domain}

		serviceInstance := models.ServiceInstanceFields{}
		serviceInstance.Name = "service1"
		serviceInstance.Guid = "service1-guid"
		services := []models.ServiceInstanceFields{serviceInstance}

		space := models.Space{}
		space.Name = "space1"
		space.Organization = org
		space.Applications = apps
		space.Domains = domains
		space.ServiceInstances = services

		requirementsFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true, Space: space}
		ui := callShowSpace([]string{"space1"}, requirementsFactory)
		Expect(ui.Outputs).To(ContainSubstrings(
			[]string{"Getting info for space", "space1", "my-org", "my-user"},
			[]string{"OK"},
			[]string{"space1"},
			[]string{"Org", "my-org"},
			[]string{"Apps", "app1"},
			[]string{"Domains", "domain1"},
			[]string{"Services", "service1"},