Esempio n. 1
0
			testassert.SliceContains(ui.Outputs, testassert.Lines{{"FAILED"}})
		})

		It("TestTargetOrganizationWhenOrgNotFound", func() {
			orgRepo.FindByNameNotFound = true

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

			testassert.SliceContains(ui.Outputs, testassert.Lines{
				{"FAILED"},
				{"my-organization", "not found"},
			})
		})

		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"
Esempio n. 2
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	testapi "testhelpers/api"
	testassert "testhelpers/assert"
	testconfig "testhelpers/configuration"
	testterm "testhelpers/terminal"
)

var _ = Describe("Testing with ginkgo", func() {
	var config configuration.ReadWriter
	var ui *testterm.FakeUI

	BeforeEach(func() {
		ui = new(testterm.FakeUI)
		config = testconfig.NewRepository()
		config.SetOrganizationFields(models.OrganizationFields{Guid: "the-org-guid"})
	})

	It("succeeds when the domain is found", func() {
		domain := models.DomainFields{Name: "example.com", Guid: "domain-guid"}
		domainRepo := &testapi.FakeDomainRepository{FindByNameInOrgDomain: domain}
		domainReq := NewDomainRequirement("example.com", ui, config, domainRepo)
		success := domainReq.Execute()

		Expect(success).To(BeTrue())
		Expect(domainRepo.FindByNameInOrgName).To(Equal("example.com"))
		Expect(domainRepo.FindByNameInOrgGuid).To(Equal("the-org-guid"))
		Expect(domainReq.GetDomain()).To(Equal(domain))
	})

	It("fails when the domain is not found", func() {
Esempio n. 3
0
			It("tells the user the api version", func() {
				testassert.SliceContains(output, testassert.Lines{
					{"API version:", "☃☃☃"},
				})
			})

			It("tells the user which user is logged in", func() {
				testassert.SliceContains(output, testassert.Lines{
					{"User:"******"my-user-email"},
				})
			})

			Context("when an org is targeted", func() {
				BeforeEach(func() {
					config.SetOrganizationFields(models.OrganizationFields{
						Name: "org-name",
						Guid: "org-guid",
					})
				})

				It("tells the user which org is targeted", func() {
					testassert.SliceContains(output, testassert.Lines{
						{"Org:", "org-name"},
					})
				})
			})

			Context("when a space is targeted", func() {
				BeforeEach(func() {
					config.SetSpaceFields(models.SpaceFields{
						Name: "my-space",
						Guid: "space-guid",
Esempio n. 4
0
		testServer.Close()
	})

	Describe("updating the endpoints", func() {
		It("stores the data from the /info api in the config", func() {
			testServerFn = validApiInfoEndpoint

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

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

			config.SetOrganizationFields(org)
			config.SetSpaceFields(space)

			repo.UpdateEndpoint(testServer.URL)

			Expect(config.AccessToken()).To(Equal(""))
			Expect(config.AuthorizationEndpoint()).To(Equal("https://login.example.com"))
			Expect(config.LoggregatorEndpoint()).To(Equal("wss://loggregator.foo.example.org:4443"))
			Expect(config.ApiEndpoint()).To(Equal(testServer.URL))
			Expect(config.ApiVersion()).To(Equal("42.0.0"))
			Expect(config.HasOrganization()).To(BeFalse())
			Expect(config.HasSpace()).To(BeFalse())
		})

		It("TestUpdateEndpointWhenUrlIsAlreadyTargeted", func() {
			testServerFn = validApiInfoEndpoint
Esempio n. 5
0
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
	})

	It("fails with usage if no arguments are given", func() {
		runCommand()
		Expect(ui.FailedWithUsage).To(BeTrue())
	})

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

		Context("when deleting the currently targeted org", func() {
			It("untargets the deleted org", func() {
				config.SetOrganizationFields(orgRepo.Organizations[0].OrganizationFields)
				runCommand("org-to-delete")

				Expect(config.OrganizationFields()).To(Equal(models.OrganizationFields{}))
				Expect(config.SpaceFields()).To(Equal(models.SpaceFields{}))
			})
		})

		Context("when deleting an org that is not targeted", func() {
			BeforeEach(func() {
				otherOrgFields := models.OrganizationFields{}
				otherOrgFields.Guid = "some-other-org-guid"
				otherOrgFields.Name = "some-other-org"
				config.SetOrganizationFields(otherOrgFields)

				spaceFields := models.SpaceFields{}
Esempio n. 6
0
			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"},
			})

			Expect(requirementsFactory.OrganizationName).To(Equal("the-old-org-name"))
			Expect(orgRepo.RenameOrganizationGuid).To(Equal("the-old-org-guid"))
			Expect(orgRepo.RenameNewName).To(Equal("the-new-org-name"))
			Expect(configRepo.OrganizationFields().Name).To(Equal(targetedOrgName))
		})

		Describe("when the organization is currently targetted", func() {
			It("updates the name of the org in the config", func() {
				configRepo.SetOrganizationFields(models.OrganizationFields{
					Guid: "the-old-org-guid",
					Name: "the-old-org-name",
				})
				callRenameOrg([]string{"the-old-org-name", "the-new-org-name"})
				Expect(configRepo.OrganizationFields().Name).To(Equal("the-new-org-name"))
			})
		})
	})
})
Esempio n. 7
0
			Expect(Config.RefreshToken()).To(Equal("my_refresh_token"))

			Expect(endpointRepo.UpdateEndpointReceived).To(Equal("api.example.com"))
			Expect(authRepo.AuthenticateArgs.Credentials).To(Equal(map[string]string{
				"username": "******",
				"password": "******",
			}))

			Expect(orgRepo.FindByNameName).To(Equal("my-org"))
			Expect(spaceRepo.FindByNameName).To(Equal("my-space"))

			Expect(ui.ShowConfigurationCalled).To(BeTrue())
		})

		It("doesn't ask the user to select an org if they have one in their config", func() {
			Config.SetOrganizationFields(org2.OrganizationFields)

			Flags = []string{"-s", "my-space"}
			ui.Inputs = []string{"http://api.example.com", "*****@*****.**", "password"}

			orgRepo.FindByNameOrganization = models.Organization{}

			l := NewLogin(ui, Config, authRepo, endpointRepo, orgRepo, spaceRepo)
			testcmd.RunCommand(l, testcmd.NewContext("login", Flags), nil)

			Expect(Config.ApiEndpoint()).To(Equal("http://api.example.com"))
			Expect(Config.OrganizationFields().Guid).To(Equal("my-org-guid"))
			Expect(Config.SpaceFields().Guid).To(Equal("my-space-guid"))
			Expect(Config.AccessToken()).To(Equal("my_access_token"))
			Expect(Config.RefreshToken()).To(Equal("my_refresh_token"))