示例#1
0
func main() {
	b := devices.Bridge{}

	for i := 0; i < 10; i++ {
		_, subnet, _ := net.ParseCIDR("2.3.4.5/30")
		if _, err := b.Create("testbridge"+os.Args[1], net.ParseIP("1.2.3.4"), subnet); err != nil {
			fmt.Println(os.Stderr, "create bridge: ", err)
			os.Exit(2)
		}

		if err := b.Destroy("testbridge" + os.Args[1]); err != nil {
			fmt.Println(os.Stderr, "destroy bridge: ", err)
			os.Exit(3)
		}
	}
}
				Expect(addrs[0].String()).To(Equal(addr))
			})
		})
	})

	Describe("Destroy", func() {
		Context("when the bridge exists", func() {
			It("deletes it", func() {
				br, err := b.Create(name, ip, subnet)
				Expect(err).ToNot(HaveOccurred())

				// sanity check
				Expect(interfaceNames()).To(ContainElement(name))

				// delete
				Expect(b.Destroy(br.Name)).To(Succeed())

				// should be gone
				Eventually(interfaceNames).ShouldNot(ContainElement(name))
			})
		})

		Context("when the bridge does not exist", func() {
			It("does not return an error (because Destroy should be idempotent)", func() {
				Expect(b.Destroy("something")).To(Succeed())
			})
		})
	})
})

func interfaceNames() []string {