It("exits", func() { test_helpers.ExecuteCommandWithArgs(targetCommand, []string{"myapi.com"}) Eventually(outputBuffer).Should(test_helpers.SayLine("some error")) verifyOldTargetStillSet() Expect(fakeExitHandler.ExitCalledWith).To(Equal([]int{exit_codes.FileSystemError})) }) }) }) Context("when the receptor requires authentication", func() { BeforeEach(func() { fakeTargetVerifier.VerifyTargetReturns(true, false, nil) fakeBlobStoreVerifier.VerifyReturns(true, nil) fakePasswordReader.PromptForPasswordReturns("testpassword") }) It("prompts for credentials and stores them in the config", func() { doneChan := test_helpers.AsyncExecuteCommandWithArgs(targetCommand, []string{"myapi.com"}) Eventually(outputBuffer).Should(test_helpers.Say("Username: "******"testusername\n")) Eventually(doneChan, 3).Should(BeClosed()) Expect(config.Target()).To(Equal("myapi.com")) Expect(config.Receptor()).To(Equal("http://*****:*****@receptor.myapi.com")) Expect(outputBuffer).To(test_helpers.SayLine("API location set."))
}) It("bubbles up errors from setting the target", func() { test_helpers.ExecuteCommandWithArgs(targetCommand, []string{"myapi.com"}) Eventually(outputBuffer).Should(test_helpers.Say("FAILURE setting api")) verifyOldTargetStillSet() Expect(fakeExitHandler.ExitCalledWith).To(Equal([]int{exit_codes.FileSystemError})) }) }) }) Context("setting target that requires auth", func() { BeforeEach(func() { fakeTargetVerifier.VerifyTargetReturns(true, false, nil) fakePasswordReader.PromptForPasswordReturns("testpassword") }) It("sets the api, username, password from the target specified", func() { commandFinishChan := test_helpers.AsyncExecuteCommandWithArgs(targetCommand, []string{"myapi.com"}) Eventually(outputBuffer).Should(test_helpers.Say("Username: "******"testusername\n")) Eventually(commandFinishChan).Should(BeClosed()) Expect(config.Target()).To(Equal("myapi.com")) Expect(config.Receptor()).To(Equal("http://*****:*****@receptor.myapi.com")) Expect(outputBuffer).To(test_helpers.Say("Api Location Set"))