コード例 #1
0
func TestItDumpsAllMessagesForAnAppUser(t *testing.T) {
	expectedMessageString := "Some data"
	logMessage := messagetesthelpers.NewLogMessage(expectedMessageString, "myOtherApp")
	envelope := messagetesthelpers.MarshalledLogEnvelope(t, logMessage, SECRET)

	dataReadChannel <- envelope
	dataReadChannel <- envelope

	time.Sleep(100 * time.Millisecond)

	receivedChan := make(chan []byte, 2)
	_, stopKeepAlive, droppedChannel := testhelpers.AddWSSink(t, receivedChan, SERVER_PORT, RECENT_LOGS_PATH+"?app=myOtherApp")

	logMessages := dumpAllMessages(receivedChan)

	assert.Equal(t, len(logMessages), 2)
	messagetesthelpers.AssertProtoBufferMessageEquals(t, expectedMessageString, logMessages[len(logMessages)-1])
	select {
	case <-droppedChannel:
		// we should have been dropped
	case <-time.After(10 * time.Millisecond):
		t.Error("we should have been dropped")
	}
	stopKeepAlive <- true
}
コード例 #2
0
func TestThatItSendsLogsToProperAppSink(t *testing.T) {
	receivedChan := make(chan []byte)

	otherLogMessage := messagetesthelpers.NewLogMessage("Some other message", "otherApp")
	otherLogEnvelope := messagetesthelpers.MarshalledLogEnvelope(t, otherLogMessage, SECRET)

	expectedMessageString := "My important message"
	logEnvelope := messagetesthelpers.MarshalledLogEnvelopeForMessage(t, expectedMessageString, "myApp02", SECRET)

	_, stopKeepAlive, _ := testhelpers.AddWSSink(t, receivedChan, SERVER_PORT, TAIL_PATH+"?app=myApp02")
	WaitForWebsocketRegistration()

	dataReadChannel <- otherLogEnvelope
	dataReadChannel <- logEnvelope

	select {
	case <-time.After(1 * time.Second):
		t.Errorf("Did not get message from app sink.")
	case message := <-receivedChan:
		messagetesthelpers.AssertProtoBufferMessageEquals(t, expectedMessageString, message)
	}

	stopKeepAlive <- true
	WaitForWebsocketRegistration()
}
コード例 #3
0
ファイル: appid_test.go プロジェクト: pkdevbox/loggregatorlib
func TestFromLogEnvelopeProtobuffer(t *testing.T) {
	logMessage := testhelpers.NewLogMessage("message", "my_app_id")
	message := testhelpers.MarshalledLogEnvelope(t, logMessage, "secret")
	appid, err := FromProtobufferMessage(message)
	assert.NoError(t, err)
	assert.Equal(t, "my_app_id", appid)
}
コード例 #4
0
func TestThatItSendsAllDataToOnlyAuthoritiveMessagesWithDrainUrls(t *testing.T) {
	client1ReceivedChan := make(chan []byte)
	client2ReceivedChan := make(chan []byte)

	fakeSyslogDrain1, err := NewFakeService(client1ReceivedChan, "127.0.0.1:34569")
	defer fakeSyslogDrain1.Stop()
	assert.NoError(t, err)
	go fakeSyslogDrain1.Serve()
	<-fakeSyslogDrain1.ReadyChan

	fakeSyslogDrain2, err := NewFakeService(client2ReceivedChan, "127.0.0.1:34540")
	defer fakeSyslogDrain2.Stop()
	assert.NoError(t, err)
	go fakeSyslogDrain2.Serve()
	<-fakeSyslogDrain2.ReadyChan

	expectedMessageString := "Some Data"
	logEnvelope := messagetesthelpers.MarshalledLogEnvelopeForMessage(t, expectedMessageString, "myApp", SECRET, "syslog://localhost:34569")
	dataReadChannel <- logEnvelope

	select {
	case <-time.After(200 * time.Millisecond):
		t.Errorf("Did not get message 1")
	case message := <-client1ReceivedChan:
		assert.Contains(t, string(message), expectedMessageString)
	}

	expectedSecondMessageString := "loggregator myApp: loggregator myApp: Some More Data"
	logMessage2 := messagetesthelpers.NewLogMessage(expectedSecondMessageString, "myApp")
	sourceName := "DEA"
	logMessage2.SourceName = &sourceName
	logMessage2.DrainUrls = []string{"syslog://localhost:34540"}
	logEnvelope2 := messagetesthelpers.MarshalledLogEnvelope(t, logMessage2, SECRET)

	dataReadChannel <- logEnvelope2

	select {
	case <-time.After(200 * time.Millisecond):
		t.Errorf("Did not get message 2")
	case message := <-client1ReceivedChan:
		matched, _ := regexp.MatchString(`<14>1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}([-+]\d{2}:\d{2}) loggregator myApp DEA - - loggregator myApp: loggregator myApp: Some More Data`, string(message))
		assert.True(t, matched, string(message))
	case <-client2ReceivedChan:
		t.Error("Should not have gotten the new message in this drain")
	}
}
コード例 #5
0
func TestEndtoEndEnvelopeToMessage(t *testing.T) {
	receivedChan := make(chan []byte)
	ws, _, _ := testhelpers.AddWSSink(t, receivedChan, "8083", "/tail/?app=myApp")
	defer ws.Close()
	time.Sleep(50 * time.Millisecond)

	connection, err := net.Dial("udp", "localhost:3456")

	expectedMessageString := "Some Data"
	unmarshalledLogMessage := messagetesthelpers.NewLogMessage(expectedMessageString, "myApp")

	expectedMessage := messagetesthelpers.MarshalledLogEnvelope(t, unmarshalledLogMessage, "secret")

	_, err = connection.Write(expectedMessage)
	assert.NoError(t, err)

	messagetesthelpers.AssertProtoBufferMessageEquals(t, expectedMessageString, <-receivedChan)
}
コード例 #6
0
func TestInvalidEnvelopeEndtoEnd(t *testing.T) {
	receivedChan := make(chan []byte)
	ws, _, _ := testhelpers.AddWSSink(t, receivedChan, "8083", "/tail/?app=myApp2")
	defer ws.Close()
	time.Sleep(50 * time.Millisecond)

	connection, err := net.Dial("udp", "localhost:3456")

	expectedMessageString := "Some Data"
	unmarshalledLogMessage := messagetesthelpers.NewLogMessage(expectedMessageString, "myApp2")

	expectedMessage := messagetesthelpers.MarshalledLogEnvelope(t, unmarshalledLogMessage, "invalid")

	_, err = connection.Write(expectedMessage)
	assert.NoError(t, err)

	select {
	case _ = <-receivedChan:
		t.Error("Message should have been dropped")
	case <-time.After(2 * time.Second):
		//success
	}
}