Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
Fixes bug when there's single hijackable container
Browse files Browse the repository at this point in the history
concourse/concourse#2598

Signed-off-by: Mark Huang <[email protected]>
  • Loading branch information
Ciro S. Costa authored and mhuangpivotal committed Sep 17, 2018
1 parent 66ea602 commit 79616b2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion commands/hijack.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (command *HijackCommand) Execute([]string) error {
return err
}
} else {
chosenContainer = containers[0]
chosenContainer = hijackableContainers[0]
}

privileged := true
Expand Down
57 changes: 57 additions & 0 deletions integration/hijack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 79616b2

Please sign in to comment.