It("should enable pty when requested", func() { fakeAppExaminer.AppStatusReturns(app_examiner.AppInfo{ActualRunningInstances: 3}, nil) test_helpers.ExecuteCommandWithArgs(sshCommand, []string{"-t", "app-name", "/bin/ls"}) Expect(fakeSSH.ShellCallCount()).To(Equal(1)) _, ptyDesired := fakeSSH.ShellArgsForCall(0) Expect(ptyDesired).To(BeTrue()) }) Context("when a command is provided", func() { It("should run a command remotely instead of the login shell", func() { fakeAppExaminer.AppStatusReturns(app_examiner.AppInfo{ActualRunningInstances: 1}, nil) doneChan := test_helpers.AsyncExecuteCommandWithArgs(sshCommand, []string{"app-name", "echo", "1", "2", "3"}) Eventually(doneChan, 3).Should(BeClosed()) Expect(outputBuffer).NotTo(test_helpers.Say("Connecting to app-name")) Expect(fakeSSH.ShellCallCount()).To(Equal(1)) command, _ := fakeSSH.ShellArgsForCall(0) Expect(command).To(Equal("echo 1 2 3")) }) It("should support -- delimiter for args", func() { fakeAppExaminer.AppStatusReturns(app_examiner.AppInfo{ActualRunningInstances: 1}, nil) test_helpers.ExecuteCommandWithArgs(sshCommand, []string{"app-name", "--", "/bin/ls", "-l"}) Expect(fakeSSH.ShellCallCount()).To(Equal(1))
signalChan = make(chan os.Signal) fakeExitHandler = &fake_exit_handler.FakeExitHandler{} }) Describe("LogsCommand", func() { var logsCommand cli.Command BeforeEach(func() { commandFactory := command_factory.NewLogsCommandFactory(appExaminer, taskExaminer, terminalUI, fakeTailedLogsOutputter, fakeExitHandler) logsCommand = commandFactory.MakeLogsCommand() }) It("tails logs", func() { appExaminer.AppExistsReturns(true, nil) doneChan := test_helpers.AsyncExecuteCommandWithArgs(logsCommand, []string{"my-app-guid"}) Eventually(fakeTailedLogsOutputter.OutputTailedLogsCallCount).Should(Equal(1)) Expect(fakeTailedLogsOutputter.OutputTailedLogsArgsForCall(0)).To(Equal("my-app-guid")) Consistently(doneChan).ShouldNot(BeClosed()) }) It("handles invalid appguids", func() { test_helpers.ExecuteCommandWithArgs(logsCommand, []string{}) Expect(outputBuffer).To(test_helpers.SayIncorrectUsage()) Expect(fakeExitHandler.ExitCalledWith).To(Equal([]int{exit_codes.InvalidSyntax})) }) It("handles non existent application", func() {
) BeforeEach(func() { commandRan = false cliCommand = cli.Command{ Name: "exec", Action: func(*cli.Context) { commandRan = true }, } }) Describe("ExecuteCommandWithArgs", func() { It("executes the command", func() { test_helpers.ExecuteCommandWithArgs(cliCommand, []string{}) Expect(commandRan).To(BeTrue()) }) }) Describe("AsyncExecuteCommandWithArgs", func() { It("executes the command", func() { doneChan := test_helpers.AsyncExecuteCommandWithArgs(cliCommand, []string{}) Eventually(doneChan, 3).Should(BeClosed()) Expect(commandRan).To(BeTrue()) }) }) })
{ Hostnames: []string{"cool-web-app.192.168.11.11.xip.io", "cool-web-app-8080.192.168.11.11.xip.io"}, Port: 8080, }, }, }, }, nil) args := []string{ "--instances=10", "cool-web-app", "superfun/app", "--", "/start-me-please", } doneChan := test_helpers.AsyncExecuteCommandWithArgs(createCommand, args) Eventually(outputBuffer).Should(test_helpers.SayLine("Creating App: cool-web-app")) Expect(fakeTailedLogsOutputter.OutputTailedLogsCallCount()).To(Equal(1)) Expect(fakeTailedLogsOutputter.OutputTailedLogsArgsForCall(0)).To(Equal("cool-web-app")) Expect(fakeAppExaminer.RunningAppInstancesInfoCallCount()).To(Equal(1)) Expect(fakeAppExaminer.RunningAppInstancesInfoArgsForCall(0)).To(Equal("cool-web-app")) fakeClock.IncrementBySeconds(1) Expect(fakeTailedLogsOutputter.StopOutputtingCallCount()).To(Equal(0)) fakeAppExaminer.RunningAppInstancesInfoReturns(9, false, nil) fakeClock.IncrementBySeconds(1) Expect(doneChan).NotTo(BeClosed())
Expect(outputBuffer).To(test_helpers.SayLine("Error submitting build of droplet-name: failed")) Expect(fakeDropletRunner.UploadBitsCallCount()).To(Equal(1)) Expect(fakeDropletRunner.BuildDropletCallCount()).To(Equal(1)) Expect(fakeExitHandler.ExitCalledWith).To(Equal([]int{exit_codes.CommandFailed})) }) }) Describe("waiting for the build to finish", func() { It("polls for the build to complete, outputting logs while the build runs", func() { fakeTaskExaminer.TaskStatusReturns(task_examiner.TaskInfo{State: "PENDING"}, nil) args := []string{ "droplet-name", "http://some.url/for/buildpack", } doneChan := test_helpers.AsyncExecuteCommandWithArgs(buildDropletCommand, args) Eventually(outputBuffer).Should(test_helpers.SayLine("Submitted build of droplet-name")) Eventually(fakeTailedLogsOutputter.OutputTailedLogsCallCount).Should(Equal(1)) Expect(fakeTailedLogsOutputter.OutputTailedLogsArgsForCall(0)).To(Equal("build-droplet-droplet-name")) Eventually(fakeTaskExaminer.TaskStatusCallCount).Should(Equal(1)) Expect(fakeTaskExaminer.TaskStatusArgsForCall(0)).To(Equal("build-droplet-droplet-name")) fakeClock.IncrementBySeconds(1) Expect(doneChan).NotTo(BeClosed()) Expect(fakeTailedLogsOutputter.StopOutputtingCallCount()).To(Equal(0)) fakeTaskExaminer.TaskStatusReturns(task_examiner.TaskInfo{State: "RUNNING"}, nil)
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.")) Expect(fakePasswordReader.PromptForPasswordCallCount()).To(Equal(1)) Expect(fakePasswordReader.PromptForPasswordArgsForCall(0)).To(Equal("Password")) Expect(fakeTargetVerifier.VerifyTargetCallCount()).To(Equal(2))
Context("when a rate flag is provided", func() { var closeChan chan struct{} AfterEach(func() { go fakeExitHandler.Exit(exit_codes.Signal) Eventually(closeChan).Should(BeClosed()) }) It("dynamically displays the visualization", func() { setNumberOfRunningInstances := func(count int) { fakeAppExaminer.ListCellsReturns([]app_examiner.CellInfo{app_examiner.CellInfo{CellID: "cell-0", RunningInstances: count}, app_examiner.CellInfo{CellID: "cell-1", RunningInstances: count, Missing: true}}, nil) } setNumberOfRunningInstances(0) closeChan = test_helpers.AsyncExecuteCommandWithArgs(visualizeCommand, []string{"--rate", "2s"}) Eventually(outputBuffer).Should(test_helpers.SayLine("cell-0: " + colors.Red("empty") + cursor.ClearToEndOfLine())) Eventually(outputBuffer).Should(test_helpers.SayLine("cell-1" + colors.Red("[MISSING]") + ": " + cursor.ClearToEndOfLine())) setNumberOfRunningInstances(2) fakeClock.IncrementBySeconds(1) Consistently(outputBuffer).ShouldNot(test_helpers.Say("cell: \n")) // TODO: how would this happen fakeClock.IncrementBySeconds(1) Eventually(outputBuffer).Should(test_helpers.Say(cursor.Hide())) Eventually(outputBuffer).Should(test_helpers.Say(cursor.Up(2))) Eventually(outputBuffer).Should(test_helpers.SayLine("cell-0: " + colors.Green("••") + cursor.ClearToEndOfLine()))