import (
	"errors"
	"net"

	"github.com/cloudfoundry-incubator/ducati-daemon/lib/links"
	"github.com/cloudfoundry-incubator/ducati-daemon/lib/nl/fakes"
	"github.com/vishvananda/netlink"
	"github.com/vishvananda/netlink/nl"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Factory", func() {
	var (
		factory   *links.Factory
		netlinker *fakes.Netlinker
	)

	BeforeEach(func() {
		netlinker = &fakes.Netlinker{}
		factory = &links.Factory{
			Netlinker: netlinker,
		}
	})

	Describe("CreateBridge", func() {
		var expectedBridge *netlink.Bridge

		BeforeEach(func() {
			expectedBridge = &netlink.Bridge{
				LinkAttrs: netlink.LinkAttrs{
	"github.com/cloudfoundry-incubator/ducati-daemon/lib/neigh"
	nl_fakes "github.com/cloudfoundry-incubator/ducati-daemon/lib/nl/fakes"
	"github.com/cloudfoundry-incubator/ducati-daemon/watcher"
	"github.com/pivotal-golang/lager/lagertest"
	"github.com/vishvananda/netlink"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
)

var _ = Describe("ARPInserter", func() {
	var (
		inserter  *neigh.ARPInserter
		ns        *fakes.Namespace
		netlinker *nl_fakes.Netlinker
		vxlanLink *netlink.Vxlan
		logger    *lagertest.TestLogger
	)

	BeforeEach(func() {
		ns = &fakes.Namespace{}
		netlinker = &nl_fakes.Netlinker{}
		logger = lagertest.NewTestLogger("test")
		vxlanLink = &netlink.Vxlan{
			LinkAttrs: netlink.LinkAttrs{
				Index: 9876,
			},
		}

		ns.ExecuteStub = func(callback func(ns *os.File) error) error {
		err := mySubscriber.Subscribe(hostNS, neighChan, doneChan)
		Expect(err).NotTo(HaveOccurred())

		_, err = net.Dial("tcp", "172.17.0.105:1234")
		Expect(err).To(HaveOccurred())

		Eventually(neighChan).Should(Receive())
	})
})

var _ = Describe("Subscriber (mock messages)", func() {
	var (
		fakeNetlinker *nlfakes.Netlinker
		fakeSocket    *nlfakes.NLSocket
		targetNS      *fakes.Namespace
		mySubscriber  *subscriber.Subscriber
		neighChan     chan *watcher.Neigh
		doneChan      chan struct{}
		logger        *lagertest.TestLogger
	)

	BeforeEach(func() {
		fakeNetlinker = &nlfakes.Netlinker{}
		fakeSocket = &nlfakes.NLSocket{}
		neighChan = make(chan *watcher.Neigh, 100)
		doneChan = make(chan struct{})
		logger = lagertest.NewTestLogger("test")
		targetNS = &fakes.Namespace{}
		targetNS.ExecuteStub = func(callback func(*os.File) error) error {
			return callback(nil)
		}
package ip_test

import (
	"errors"
	"net"

	"github.com/cloudfoundry-incubator/ducati-daemon/lib/ip"
	"github.com/cloudfoundry-incubator/ducati-daemon/lib/nl/fakes"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/vishvananda/netlink"
)

var _ = Describe("AddressManager", func() {
	var netlinker *fakes.Netlinker
	var addressManager *ip.AddressManager

	BeforeEach(func() {
		netlinker = &fakes.Netlinker{}
		addressManager = &ip.AddressManager{
			Netlinker: netlinker,
		}
	})

	Describe("AddAddress", func() {
		var (
			link    netlink.Link
			address *net.IPNet
		)

		BeforeEach(func() {