示例#1
0
					cliApp.Action = func(context *cli.Context) {
						commandRan = true
					}

					err := cliApp.Run([]string{"ltc", "buy-me-a-pony"})
					Expect(err).NotTo(HaveOccurred())

					Expect(commandRan).To(BeTrue())
					Expect(fakeTargetVerifier.VerifyTargetCallCount()).To(Equal(0))
				})
			})

			Context("Any other command", func() {
				Context("when targeted receptor is up and we are authorized", func() {
					It("executes the command", func() {
						fakeTargetVerifier.VerifyTargetReturns(true, true, nil)

						cliConfig.SetTarget("my-lattice.example.com")
						Expect(cliConfig.Save()).To(Succeed())

						commandRan := false
						cliApp.Commands = []cli.Command{
							cli.Command{
								Name: "print-a-unicorn",
								Action: func(ctx *cli.Context) {
									commandRan = true
								},
							},
						}

						err := cliApp.Run([]string{"ltc", "print-a-unicorn"})
			Context("when no target is set", func() {
				BeforeEach(func() {
					config.SetTarget("")
					Expect(config.Save()).To(Succeed())
				})

				It("informs the user the target is not set", func() {
					Expect(string(outputBuffer.Contents())).To(BeEmpty())
				})
			})
		})

		Context("when initially connecting to the receptor without authentication", func() {
			BeforeEach(func() {
				fakeTargetVerifier.VerifyTargetReturns(true, true, nil)
				fakeBlobStoreVerifier.VerifyReturns(true, nil)
			})

			It("saves the new receptor target", func() {
				test_helpers.ExecuteCommandWithArgs(targetCommand, []string{"myapi.com"})

				Expect(fakeTargetVerifier.VerifyTargetCallCount()).To(Equal(1))
				Expect(fakeTargetVerifier.VerifyTargetArgsForCall(0)).To(Equal("http://receptor.myapi.com"))

				newConfig := config_package.New(configPersister)
				Expect(newConfig.Load()).To(Succeed())
				Expect(newConfig.Receptor()).To(Equal("http://receptor.myapi.com"))
			})

			It("clears out existing saved target credentials", func() {