}) Context("when namespace execute fails", func() { BeforeEach(func() { namespace.ExecuteReturns(errors.New("go away")) }) It("wraps and propagates the error", func() { err := inNamespace.Execute(context) Expect(err).To(MatchError("execute in namespace: go away")) }) }) Context("when the target command fails", func() { BeforeEach(func() { command.ExecuteReturns(errors.New("i died")) }) It("wraps and propagates the error", func() { err := inNamespace.Execute(context) Expect(err).To(MatchError("execute in namespace: i died")) }) }) Describe("String", func() { It("describes itself", func() { Expect(inNamespace.String()).To(Equal("ip netns exec namespace-name some-command")) }) }) })
Expect(err).NotTo(HaveOccurred()) Expect(command1.ExecuteCallCount()).To(Equal(1)) Expect(command1.ExecuteArgsForCall(0)).To(Equal(context)) Expect(command2.ExecuteCallCount()).To(Equal(1)) Expect(command2.ExecuteArgsForCall(0)).To(Equal(context)) Expect(command3.ExecuteCallCount()).To(Equal(1)) Expect(command3.ExecuteArgsForCall(0)).To(Equal(context)) }) }) Context("when a command returns an error", func() { BeforeEach(func() { command2.ExecuteReturns(errors.New("go away")) }) It("wraps the error with contextual information", func() { err := all.Execute(context) Expect(err.Error()).To(Equal("go away: commands: (\n" + " some-command 1 &&\n" + "--> some-command 2 &&\n" + " some-command 3\n" + ")")) }) It("makes the original error available", func() { err := all.Execute(context) Expect(err).To(HaveOccurred())