}) Context("when namespace execution fails", func() { BeforeEach(func() { sbNamespace.ExecuteReturns(errors.New("boysenberry")) }) It("returns a meaningful error", func() { err := sb.Setup() Expect(err).To(MatchError("setup failed: boysenberry")) }) }) Context("when setting the link up fails", func() { BeforeEach(func() { linkFactory.SetUpReturns(errors.New("tomato")) }) It("returns a meaningful error", func() { err := sb.Setup() Expect(err).To(MatchError("setup failed: set link up: tomato")) }) }) }) Describe("Namespace", func() { It("returns the sandbox namespace", func() { ns := sb.Namespace() Expect(ns).To(Equal(sbNamespace)) }) })
}) Context("when adding the address fails", func() { BeforeEach(func() { addressManager.AddAddressReturns(errors.New("pineapple")) }) It("returns a meaningful error", func() { err := startDNS.Execute(context) Expect(err).To(MatchError("namespace execute: add address: pineapple")) }) }) Context("when setting the link up fails", func() { BeforeEach(func() { linkFactory.SetUpReturns(errors.New("pineapple")) }) It("returns a meaningful error", func() { err := startDNS.Execute(context) Expect(err).To(MatchError("namespace execute: set up: pineapple")) }) }) Context("when creating the listener fails", func() { BeforeEach(func() { listenerFactory.ListenUDPReturns(nil, errors.New("cantelope")) }) It("returns a meaningful error", func() { err := startDNS.Execute(context)
context.LinkFactoryReturns(linkFactory) setLinkUp = commands.SetLinkUp{ LinkName: "link-name", } }) It("sets the link up", func() { err := setLinkUp.Execute(context) Expect(err).NotTo(HaveOccurred()) Expect(linkFactory.SetUpCallCount()).To(Equal(1)) Expect(linkFactory.SetUpArgsForCall(0)).To(Equal("link-name")) }) Context("when setting the link UP fails", func() { It("wraps and propagates the error", func() { linkFactory.SetUpReturns(errors.New("welp")) err := setLinkUp.Execute(context) Expect(err).To(MatchError("set link up: welp")) }) }) Describe("String", func() { It("describes itself", func() { Expect(setLinkUp.String()).To(Equal("ip link set link-name up")) }) }) })