BeforeEach(func() { 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"))
HostNamespace: hostNS, Watcher: fakeWatcher, SandboxName: "some-sandbox", VxlanLinkName: "some-vxlan-name", } hostNS.ExecuteStub = func(callback func(_ *os.File) error) error { return callback(nil) } }) Describe("Execute", func() { It("it calls StartMonitor inside the HostNamespace", func() { 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))