hostNS.ExecuteStub = func(callback func(_ *os.File) error) error { Expect(fakeWatcher.StartMonitorCallCount()).To(Equal(0)) callback(nil) Expect(fakeWatcher.StartMonitorCallCount()).To(Equal(1)) return nil } err := startMonitor.Execute(context) Expect(err).NotTo(HaveOccurred()) Expect(sandboxRepository.GetCallCount()).To(Equal(1)) Expect(sandboxRepository.GetArgsForCall(0)).To(Equal("some-sandbox")) Expect(hostNS.ExecuteCallCount()).To(Equal(1)) ns, linkName := fakeWatcher.StartMonitorArgsForCall(0) Expect(ns).To(Equal(sandboxNS)) Expect(linkName).To(Equal("some-vxlan-name")) }) Context("when getting the sandbox namespace fails", func() { BeforeEach(func() { sandboxRepository.GetReturns(nil, errors.New("potato")) }) It("wraps and propogates the error", func() { err := startMonitor.Execute(context) Expect(err).To(MatchError("getting sandbox namespace: potato")) }) })
watcher = &fakes.MissWatcher{} monitorReloader = &reloader.Reloader{ Watcher: watcher, } ns = &fakes.Namespace{} ns.NameReturns("/some/sbox/path/vni-some-sandbox") }) Describe("Callback", func() { It("restart the monitor for the given namespace", func() { err := monitorReloader.Callback(ns) Expect(err).NotTo(HaveOccurred()) Expect(watcher.StartMonitorCallCount()).To(Equal(1)) calledNS, vxlanDev := watcher.StartMonitorArgsForCall(0) Expect(calledNS).To(Equal(ns)) Expect(vxlanDev).To(Equal("vxlansome-sandbox")) }) Context("failure cases", func() { It("returns an error when the sandbox name is not valid", func() { ns.NameReturns("some-invalid-name") err := monitorReloader.Callback(ns) Expect(err).To(MatchError("get vxlan name: not a valid sandbox name")) }) It("returns an error when monitor does not start", func() { watcher.StartMonitorReturns(errors.New("some-fake-error")) err := monitorReloader.Callback(ns)
DeviceName: "some-vxlan-name", } }) JustBeforeEach(func() { process = ifrit.Invoke(nsWatcher) }) AfterEach(func() { process.Signal(syscall.SIGINT) }) It("calls StartMonitor with the right arguments", func() { Eventually(missWatcher.StartMonitorCallCount).Should(Equal(1)) n, vxlanName := missWatcher.StartMonitorArgsForCall(0) Expect(n).To(Equal(ns)) Expect(vxlanName).To(Equal("some-vxlan-name")) }) Context("when StartMonitor fails", func() { BeforeEach(func() { missWatcher.StartMonitorReturns(errors.New("pineapple")) }) It("returns a meaningful error", func() { errCh := process.Wait() Eventually(errCh).Should(Receive(MatchError("start monitor: pineapple"))) }) It("does not close the ready channel", func() {