Example #1
0
				Expect(ui.Outputs).To(ContainSubstrings(
					[]string{"Select an org"},
					[]string{"1. some-org"},
					[]string{"2. my-new-org"},
					[]string{"Select a space"},
					[]string{"1. my-space"},
					[]string{"2. some-space"},
				))

				Expect(Config.OrganizationFields().Guid).To(Equal("my-new-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"))

				Expect(endpointRepo.UpdateEndpointCallCount()).To(Equal(1))
				Expect(endpointRepo.UpdateEndpointArgsForCall(0)).To(Equal("api.example.com"))

				Expect(orgRepo.FindByNameArgsForCall(0)).To(Equal("my-new-org"))
				Expect(spaceRepo.FindByNameArgsForCall(0)).To(Equal("my-space"))

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

			It("lets the user select an org and space by name", func() {
				ui.Inputs = []string{"api.example.com", "*****@*****.**", "password", "my-new-org", "my-space"}
				orgRepo.FindByNameReturns(org2, nil)

				testcmd.RunCliCommand("login", Flags, nil, updateCommandDependency, false)

				Expect(ui.Outputs).To(ContainSubstrings(
					[]string{"Select an org"},
Example #2
0
	Context("when the user provides the --skip-ssl-validation flag", func() {
		It("updates the SSLDisabled field in config", func() {
			config.SetSSLDisabled(false)
			callApi([]string{"--skip-ssl-validation", "https://example.com"}, config, endpointRepo)

			Expect(config.IsSSLDisabled()).To(Equal(true))
		})
	})

	Context("the user provides an endpoint", func() {
		Describe("when the user passed in the skip-ssl-validation flag", func() {
			It("disables SSL validation in the config", func() {
				callApi([]string{"--skip-ssl-validation", "https://example.com"}, config, endpointRepo)

				Expect(endpointRepo.UpdateEndpointCallCount()).To(Equal(1))
				Expect(endpointRepo.UpdateEndpointArgsForCall(0)).To(Equal("https://example.com"))
				Expect(config.IsSSLDisabled()).To(BeTrue())
			})
		})

		Context("when the user passed in the unset flag", func() {
			Context("when the config.ApiEndpoint is set", func() {
				BeforeEach(func() {
					config.SetApiEndpoint("some-silly-thing")
					ui = new(testterm.FakeUI)
				})

				It("unsets the ApiEndpoint", func() {
					callApi([]string{"--unset", "https://example.com"}, config, endpointRepo)

					Expect(ui.Outputs).To(ContainSubstrings(
Example #3
0
					[]string{"Incorrect Usage. No argument required"},
				))
			})
		})
	})

	Describe("Execute", func() {
		BeforeEach(func() {
			_, err := cmd.Requirements(factory, flagContext)
			Expect(err).NotTo(HaveOccurred())
		})

		It("tries to update the endpoint", func() {
			cmd.Execute(flagContext)
			Expect(endpointRepo.UpdateEndpointCallCount()).To(Equal(1))
			Expect(endpointRepo.UpdateEndpointArgsForCall(0)).To(Equal("fake-api-endpoint"))
		})

		Context("when updating the endpoint succeeds", func() {
			BeforeEach(func() {
				endpointRepo.UpdateEndpointReturns("updated-endpoint", nil)
			})

			It("tries to refresh the auth token", func() {
				cmd.Execute(flagContext)
				Expect(authRepo.RefreshAuthTokenCallCount()).To(Equal(1))
			})

			Context("when refreshing the token fails with an error", func() {
				BeforeEach(func() {
					authRepo.RefreshAuthTokenReturns("", errors.New("auth-error"))