예제 #1
0
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
			reqFactory.TargetedOrgSuccess = false
			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"
			reqFactory.Space = space
		})

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

			testassert.SliceContains(ui.Outputs, testassert.Lines{
				{"Renaming space", "the-old-space-name", "my-new-space", "my-org", "my-user"},
				{"OK"},
			})

			Expect(spaceRepo.RenameSpaceGuid).To(Equal("the-old-space-guid"))
예제 #3
0
		})

		It("TestTargetSpaceWhenNoOrganizationIsSelected", func() {
			config.SetOrganizationFields(models.OrganizationFields{})

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

			testassert.SliceContains(ui.Outputs, testassert.Lines{
				{"FAILED"},
				{"An org must be targeted before targeting a space"},
			})
			Expect(config.OrganizationFields().Guid).To(Equal(""))
		})

		It("TestTargetSpaceWhenUserHasAccess", func() {
			space := models.Space{}
			space.Name = "my-space"
			space.Guid = "my-space-guid"

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

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

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

		It("TestTargetSpaceWhenUserDoesNotHaveAccess", func() {
			config.SetSpaceFields(models.SpaceFields{})
예제 #4
0
			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{
			"username": configuration.AuthPrompt{
				DisplayName: "Username",
				Type:        configuration.AuthPromptTypeText,
			},
			"password": configuration.AuthPrompt{
				DisplayName: "Password",
				Type:        configuration.AuthPromptTypePassword,
예제 #5
0
		app := models.ApplicationFields{}
		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

		reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true, Space: space}
		ui := callShowSpace([]string{"space1"}, reqFactory)
		testassert.SliceContains(ui.Outputs, testassert.Lines{
			{"Getting info for space", "space1", "my-org", "my-user"},
			{"OK"},
			{"space1"},
			{"Org", "my-org"},
			{"Apps", "app1"},
			{"Domains", "domain1"},
예제 #6
0
func defaultDeleteSpaceSpace() models.Space {
	space := models.Space{}
	space.Name = "space-to-delete"
	space.Guid = "space-to-delete-guid"
	return space
}
예제 #7
0
		reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true}
		callSpaces([]string{}, reqFactory, config, spaceRepo)
		Expect(testcmd.CommandDidPassRequirements).To(BeTrue())

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

		reqFactory = &testreq.FakeReqFactory{LoginSuccess: false, TargetedOrgSuccess: true}
		callSpaces([]string{}, reqFactory, 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()
		reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true}

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

		testassert.SliceContains(ui.Outputs, testassert.Lines{
예제 #8
0
		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{}
		user4.Username = "******"
예제 #9
0
파일: space_test.go 프로젝트: nota-ja/cli
package requirements_test

import (
	"cf/models"
	. "cf/requirements"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	testapi "testhelpers/api"
	testassert "testhelpers/assert"
	testterm "testhelpers/terminal"
)

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() {