github.com/geofffranks/garden-linux@v0.0.0-20160715111146-26c893169cfa/network/devices/veth_linux_test.go (about) 1 package devices_test 2 3 import ( 4 "fmt" 5 "net" 6 7 "code.cloudfoundry.org/garden-linux/network/devices" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("Veth Pair Creation", func() { 13 var ( 14 v devices.VethCreator 15 hostName, containerName string 16 ) 17 18 f := func(i *net.Interface, _ error) *net.Interface { 19 return i 20 } 21 22 l := func(_, _ interface{}, e error) error { 23 return e 24 } 25 26 BeforeEach(func() { 27 hostName = fmt.Sprintf("doesntexist-h-%d", GinkgoParallelNode()) 28 containerName = fmt.Sprintf("doesntexist-c-%d", GinkgoParallelNode()) 29 }) 30 31 AfterEach(func() { 32 Expect(cleanup(hostName)).To(Succeed()) 33 Expect(cleanup(containerName)).To(Succeed()) 34 }) 35 36 Context("when neither host already exists", func() { 37 It("creates both interfaces in the host", func() { 38 Expect(l(v.Create(hostName, containerName))).To(Succeed()) 39 Expect(net.InterfaceByName(hostName)).ToNot(BeNil()) 40 Expect(net.InterfaceByName(containerName)).ToNot(BeNil()) 41 }) 42 43 It("returns the created interfaces", func() { 44 a, b, err := v.Create(hostName, containerName) 45 Expect(err).ToNot(HaveOccurred()) 46 47 Expect(a).To(Equal(f(net.InterfaceByName(hostName)))) 48 Expect(b).To(Equal(f(net.InterfaceByName(containerName)))) 49 }) 50 }) 51 52 Context("when one of the interfaces already exists", func() { 53 It("returns an error", func() { 54 Expect(l(v.Create(hostName, containerName))).To(Succeed()) 55 Expect(l(v.Create(hostName, containerName))).ToNot(Succeed()) 56 }) 57 }) 58 })