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()
		heartbeater = natbeat.New(fakeNatsClient, expectedRegistryMsg, initialRegisterInterval, logger)
		registrations = make(chan natbeat.RegistryMessage, 1)

		fakeNatsClient.Subscribe("router.register", func(msg *nats.Msg) {
			registration := natbeat.RegistryMessage{}
			fromJson(msg.Data, &registration)
			registrations <- registration
		})
	})

	JustBeforeEach(func() {
		heartbeaterProcess = ifrit.Invoke(heartbeater)
		Eventually(heartbeaterProcess.Ready()).Should(BeClosed())
	})
Beispiel #2
0
func TestCanPassFakeYagnatsAsNATSClient(t *testing.T) {
	FunctionTakingNATSClient(diegonats.NewFakeClient())
}