Expect(err).NotTo(HaveOccurred()) Expect(namespace.ExecuteCallCount()).To(Equal(1)) }) It("executes the command with the correct context", func() { err := inNamespace.Execute(context) Expect(err).NotTo(HaveOccurred()) Expect(command.ExecuteCallCount()).To(Equal(1)) Expect(command.ExecuteArgsForCall(0)).To(Equal(context)) }) 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(ns.ExecuteCallCount()).To(Equal(2)) Expect(netlinker.SetNeighArgsForCall(1)).To(Equal(&netlink.Neigh{ LinkIndex: 9876, HardwareAddr: neigh.HardwareAddr, Family: syscall.AF_BRIDGE, State: netlink.NUD_REACHABLE, Type: 0, Flags: netlink.NTF_SELF, IP: neighbor.VTEP, })) }) Context("when executing in namespace fails", func() { BeforeEach(func() { ns.ExecuteReturns(errors.New("peppers")) }) It("returns the error", func() { inserter.HandleResolvedNeighbors(ready, ns, "some-vxlan-name", resolved) Eventually(ready).Should(Receive(MatchError("namespace execute failed: peppers"))) }) }) Context("when setting a neighbor entry fails", func() { BeforeEach(func() { netlinker.SetNeighStub = func(n *netlink.Neigh) error { if netlinker.SetNeighCallCount() == 1 { return errors.New("go huskies") } return nil
written, err := nsWriter.Write([]byte{}) Expect(err).NotTo(HaveOccurred()) Expect(written).To(Equal(100)) }) It("logs the operation", func() { nsWriter.Write([]byte{}) Expect(logger).To(gbytes.Say("write.write-called.*namespace.*some-inode")) Expect(logger).To(gbytes.Say("write.write-complete.*namespace.*some-inode")) }) Context("when setting the namespae fails", func() { BeforeEach(func() { ns.ExecuteReturns(errors.New("peanuts")) }) It("returns a meaningful error", func() { _, err := nsWriter.Write([]byte{}) Expect(err).To(MatchError("namespace execute: peanuts")) }) It("logs the error", func() { nsWriter.Write([]byte{}) Expect(logger).To(gbytes.Say("write.namespace-execute-failed.*peanuts")) }) }) Context("when the wrapped writer fails", func() {
return err } err := sb.Setup() Expect(err).NotTo(HaveOccurred()) Expect(sbNamespace.ExecuteCallCount()).To(Equal(1)) Expect(linkFactory.SetUpCallCount()).To(Equal(1)) linkName := linkFactory.SetUpArgsForCall(0) Expect(linkName).To(Equal("lo")) }) 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()