Context("when the sandbox has already been torn down", func() { BeforeEach(func() { err := sb.Teardown() Expect(err).NotTo(HaveOccurred()) }) It("returns an AlreadyDestroyedError", func() { err := sb.Teardown() Expect(err).To(Equal(sandbox.AlreadyDestroyedError)) }) It("does NOT try to stop the monitor AGAIN", func() { err := sb.Teardown() Expect(err).To(HaveOccurred()) Expect(watcher.StopMonitorCallCount()).To(Equal(1)) }) }) Context("when there is an error stopping the miss watcher", func() { It("returns a meaningful error", func() { watcher.StopMonitorReturns(errors.New("spaghetti")) err := sb.Teardown() Expect(err).To(MatchError("stop monitor: spaghetti")) }) }) }) })
}) }) It("calls StopMonitor when signaled", func() { Eventually(process.Ready()).Should(BeClosed()) errCh := process.Wait() Consistently(errCh).ShouldNot(Receive()) process.Signal(os.Kill) Eventually(missWatcher.StopMonitorCallCount).Should(Equal(1)) Eventually(errCh).Should(Receive(BeNil())) namespace := missWatcher.StopMonitorArgsForCall(0) Expect(namespace).To(Equal(ns)) }) Context("when StopMonitor fails", func() { BeforeEach(func() { missWatcher.StopMonitorReturns(errors.New("kiwi")) }) It("returns a meaningful error", func() { errCh := process.Wait() process.Signal(os.Kill) Eventually(errCh).Should(Receive(MatchError("stop monitor: kiwi"))) }) }) })