示例#1
0
			Expect(err).ToNot(HaveOccurred())
			Eventually(cmd, "5s").Should(gexec.Exit(0))
		})

		It("moves the interface in to the given namespace by pid", func() {
			// look at this perfectly ordinary hat
			netns, err := gexec.Start(exec.Command("ip", "netns", "exec", "gdnsetnstest", "sleep", "6312736"), GinkgoWriter, GinkgoWriter)
			Expect(err).ToNot(HaveOccurred())
			defer netns.Kill()

			// (it has the following fd)
			f, err := os.Open("/var/run/netns/gdnsetnstest")
			Expect(err).ToNot(HaveOccurred())

			// I wave the magic wand
			Expect(l.SetNs(intf, int(f.Fd()))).To(Succeed())

			// the bunny has vanished! where is the bunny?
			intfs, _ := net.Interfaces()
			Expect(intfs).ToNot(ContainElement(intf))

			// oh my word it's in the hat!
			session, err := gexec.Start(exec.Command("sh", "-c", fmt.Sprintf("ip netns exec gdnsetnstest ifconfig %s", name)), GinkgoWriter, GinkgoWriter)
			Expect(err).ToNot(HaveOccurred())
			Eventually(session, "5s").Should(gexec.Exit(0))
		})

		Context("when the interface does not exist", func() {
			It("returns the error", func() {
				Expect(l.SetNs(&net.Interface{Name: "something"}, 1234)).To(MatchError("devices: Link not found"))
			})