示例#1
0
			waitChan := make(chan struct{})
			fakeSession.ShellStub = func() error {
				waitChan <- struct{}{}
				waitChan <- struct{}{}
				return nil
			}

			Expect(appSSH.Connect("some-app-name", 100, config)).To(Succeed())

			go func() {
				appSSH.Shell("", true)
			}()

			<-waitChan

			fakeExitHandler.Exit(123)

			Eventually(fakeTerm.RestoreTerminalCallCount).Should(Equal(1))
			actualFD, actualState := fakeTerm.RestoreTerminalArgsForCall(0)
			Expect(actualFD).To(Equal(os.Stdin.Fd()))
			Expect(reflect.ValueOf(actualState).Pointer()).To(Equal(reflect.ValueOf(state).Pointer()))

			<-waitChan
		})

		Context("when we fail to set the raw terminal", func() {
			It("does not restore the terminal at the end", func() {
				fakeTerm.SetRawTerminalReturns(nil, errors.New("some error"))

				Expect(appSSH.Connect("some-app-name", 100, config)).To(Succeed())
				Expect(appSSH.Shell("", true)).To(Succeed())
				test_helpers.ExecuteCommandWithArgs(visualizeCommand, []string{})

				Expect(outputBuffer).To(test_helpers.Say("Error visualizing: The list was lost"))
				Expect(outputBuffer).To(test_helpers.Say(cursor.ClearToEndOfLine()))
				Expect(outputBuffer).To(test_helpers.SayNewLine())

				// TODO: this should return non-zero, but it's shared with refresh view
				//   which should continue to retry in the event on an error and not exit
			})
		})

		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)