existingBridge *net.Interface ) BeforeEach(func() { var err error netnsFD, err = ioutil.TempFile("", "") Expect(err).NotTo(HaveOccurred()) existingBridge = &net.Interface{Name: "bridge"} }) JustBeforeEach(func() { linkConfigurer.InterfaceByNameFunc = func(name string) (*net.Interface, bool, error) { if name == "bridge" { return existingBridge, true, nil } return nil, false, nil } }) AfterEach(func() { Expect(os.Remove(netnsFD.Name())).To(Succeed()) }) It("creates a virtual ethernet pair", func() { config.HostIntf = "host" config.BridgeName = "bridge" config.ContainerIntf = "container" Expect(configurer.Apply(config, netnsFD)).To(Succeed())
BeforeEach(func() { linkApplyr = &fakedevices.FakeLink{AddIPReturns: make(map[string]error)} configurer = &configure.Container{ Link: linkApplyr, Logger: lagertest.NewTestLogger("test"), } }) Context("when the loopback device does not exist", func() { var eth *net.Interface BeforeEach(func() { linkApplyr.InterfaceByNameFunc = func(name string) (*net.Interface, bool, error) { if name != "lo" { return eth, true, nil } return nil, false, nil } }) It("returns a wrapped error", func() { err := configurer.Apply(config) Expect(err).To(MatchError(&configure.FindLinkError{Cause: nil, Role: "loopback", Name: "lo"})) }) It("does not attempt to configure other devices", func() { Expect(configurer.Apply(config)).ToNot(Succeed()) Expect(linkApplyr.SetUpCalledWith).ToNot(ContainElement(eth)) }) })