"github.com/apcera/nats"
	"github.com/cloudfoundry-incubator/route-emitter/nats_emitter"
	"github.com/cloudfoundry-incubator/route-emitter/routing_table"
	fake_metrics_sender "github.com/cloudfoundry/dropsonde/metric_sender/fake"
	"github.com/cloudfoundry/dropsonde/metrics"
	"github.com/cloudfoundry/gunk/diegonats"
	"github.com/cloudfoundry/gunk/workpool"
	"github.com/pivotal-golang/lager/lagertest"

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

var _ = Describe("NatsEmitter", func() {
	var emitter nats_emitter.NATSEmitter
	var natsClient *diegonats.FakeNATSClient
	var fakeMetricSender *fake_metrics_sender.FakeMetricSender

	messagesToEmit := routing_table.MessagesToEmit{
		RegistrationMessages: []routing_table.RegistryMessage{
			{URIs: []string{"foo.com", "bar.com"}, Host: "1.1.1.1", Port: 11},
			{URIs: []string{"baz.com"}, Host: "2.2.2.2", Port: 22},
		},
		UnregistrationMessages: []routing_table.RegistryMessage{
			{URIs: []string{"wibble.com"}, Host: "1.1.1.1", Port: 11},
			{URIs: []string{"baz.com"}, Host: "3.3.3.3", Port: 33},
		},
	}

	BeforeEach(func() {
		natsClient = diegonats.NewFakeClient()
	"fmt"
	"time"

	"github.com/apcera/nats"
	"github.com/cloudfoundry-incubator/natbeat"
	"github.com/cloudfoundry/gunk/diegonats"
	"github.com/pivotal-golang/lager"
	"github.com/tedsuo/ifrit"
	"github.com/tedsuo/ifrit/ginkgomon"

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

var _ = Describe("Heartbeater", func() {
	var fakeNatsClient *diegonats.FakeNATSClient
	var heartbeater *natbeat.Heartbeater
	var heartbeaterProcess ifrit.Process
	var registrations chan natbeat.RegistryMessage
	var initialRegisterInterval = 100 * time.Millisecond
	var expectedRegistryMsg = natbeat.RegistryMessage{
		URIs:              []string{"foo.bar.com", "example.com"},
		Host:              "1.2.3.4",
		Port:              4567,
		App:               "my-awesome-app",
		PrivateInstanceId: "deadbeef-c0ffee",
	}

	BeforeEach(func() {
		logger := lager.NewLogger("test")
		fakeNatsClient = diegonats.NewFakeClient()
		processGuid   = "process-guid-1"
		containerPort = 8080
		instanceGuid  = "instance-guid-1"
		lrpHost       = "1.2.3.4"
	)

	var (
		bbsClient      *fake_bbs.FakeClient
		natsClient     *diegonats.FakeNATSClient
		syncerRunner   *syncer.Syncer
		process        ifrit.Process
		syncMessages   routing_table.MessagesToEmit
		messagesToEmit routing_table.MessagesToEmit
		clock          *fakeclock.FakeClock
		clockStep      time.Duration
		syncInterval   time.Duration

		shutdown chan struct{}

		schedulingInfoResponse *models.DesiredLRPSchedulingInfo
		actualResponses        []*models.ActualLRPGroup

		routerStartMessages chan<- *nats.Msg
		fakeMetricSender    *fake_metrics_sender.FakeMetricSender
	)

	BeforeEach(func() {
		bbsClient = new(fake_bbs.FakeClient)
		natsClient = diegonats.NewFakeClient()

		clock = fakeclock.NewFakeClock(time.Now())