}) Context("when destroy fails", func() { BeforeEach(func() { sandboxRepo.DestroyReturns(errors.New("potato")) }) It("wraps and returns the error", func() { err := cleanupSandboxCommand.Execute(context) Expect(err).To(MatchError("sandbox destroy: potato")) }) }) Context("when there is an error destroying vxlan device", func() { BeforeEach(func() { linkFactory.DeleteLinkByNameReturns(errors.New("some-error")) }) It("checks if the link still exists", func() { cleanupSandboxCommand.Execute(context) Expect(linkFactory.ExistsCallCount()).To(Equal(1)) linkName := linkFactory.ExistsArgsForCall(0) Expect(linkName).To(Equal(cleanupSandboxCommand.VxlanDeviceName)) }) Context("when the link no longer exists", func() { BeforeEach(func() { linkFactory.ExistsReturns(false) })
context.LinkFactoryReturns(linkFactory) deleteLinkCommand = commands.DeleteLink{LinkName: "some-link-name"} }) It("calls Delete method on context.LinkFactory", func() { err := deleteLinkCommand.Execute(context) Expect(err).NotTo(HaveOccurred()) Expect(linkFactory.DeleteLinkByNameCallCount()).To(Equal(1)) Expect(linkFactory.DeleteLinkByNameArgsForCall(0)).To(Equal("some-link-name")) }) Context("when deleting the link by name fails", func() { BeforeEach(func() { linkFactory.DeleteLinkByNameReturns(errors.New("whatever")) }) It("wraps and propogates the error", func() { err := deleteLinkCommand.Execute(context) Expect(err).To(MatchError("delete link: whatever")) }) }) Describe("String", func() { It("describes itself", func() { Expect(deleteLinkCommand.String()).To(Equal("ip link del some-link-name")) }) }) })