From 79616b2348f39c74b6e3290c585a24a0faac3e3b Mon Sep 17 00:00:00 2001 From: "Ciro S. Costa" Date: Mon, 17 Sep 2018 15:27:39 -0400 Subject: [PATCH] Fixes bug when there's single hijackable container concourse/concourse#2598 Signed-off-by: Mark Huang --- commands/hijack.go | 2 +- integration/hijack_test.go | 57 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/commands/hijack.go b/commands/hijack.go index 74a2b5a..f924034 100644 --- a/commands/hijack.go +++ b/commands/hijack.go @@ -125,7 +125,7 @@ func (command *HijackCommand) Execute([]string) error { return err } } else { - chosenContainer = containers[0] + chosenContainer = hijackableContainers[0] } privileged := true diff --git a/integration/hijack_test.go b/integration/hijack_test.go index 019d2ad..a036dfa 100644 --- a/integration/hijack_test.go +++ b/integration/hijack_test.go @@ -538,6 +538,63 @@ var _ = Describe("Hijacking", func() { Expect(sess.ExitCode()).To(Equal(123)) }) }) + + Context("and only one container is in hijackable state", func() { + BeforeEach(func() { + containerList = []atc.Container{ + { + ID: "container-id-1", + WorkerName: "worker-name-1", + PipelineName: "pipeline-name-1", + JobName: "some-job", + BuildName: "1", + BuildID: 12, + Type: "get", + StepName: "some-input", + Attempt: "1.1.1", + User: user, + State: atc.ContainerStateDestroying, + }, + { + ID: "container-id-2", + WorkerName: "worker-name-2", + PipelineName: "pipeline-name-1", + JobName: "some-job", + BuildName: "2", + BuildID: 13, + Type: "put", + StepName: "some-output", + Attempt: "1.1.2", + User: user, + State: atc.ContainerStateCreated, + }, + } + }) + + It("hijacks the hijackable container", func() { + flyCmd := exec.Command(flyPath, "-t", targetName, "hijack", "-j", "pipeline-name-1/some-job") + + stdin, err := flyCmd.StdinPipe() + Expect(err).NotTo(HaveOccurred()) + + sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) + Expect(err).NotTo(HaveOccurred()) + + Eventually(hijacked).Should(BeClosed()) + + _, err = fmt.Fprintf(stdin, "some stdin") + Expect(err).NotTo(HaveOccurred()) + + Eventually(sess.Out).Should(gbytes.Say("some stdout")) + Eventually(sess.Err).Should(gbytes.Say("some stderr")) + + err = stdin.Close() + Expect(err).NotTo(HaveOccurred()) + + <-sess.Exited + Expect(sess.ExitCode()).To(Equal(123)) + }) + }) }) Context("when hijack returns a single container", func() {