Exemplo n.º 1
0
func init() {
	// This needs be unbuffered as the channel we get from the
	// agent listener is unbuffered?
	dataReadChannel = make(chan []byte, 10)
	TestSinkServer = NewSinkServer(messagestore.NewMessageStore(10), testhelpers.Logger(), testhelpers.SuccessfulAuthorizer, 50*time.Millisecond)
	go TestSinkServer.Start(dataReadChannel, "localhost:"+SERVER_PORT)
	time.Sleep(1 * time.Millisecond)
}
func TestUserRoleAccessCombinations(t *testing.T) {
	for i, test := range accessTests {
		decoder := &TestUaaTokenDecoder{test.userDetails}
		authorizer := NewLogAccessAuthorizer(decoder, "http://localhost:9876")
		result := authorizer(test.authToken, test.target, testhelpers.Logger())
		if result != test.expectedResult {
			t.Errorf("Access combination %d for %v failed.", i, test.userDetails)
		}
	}
}
Exemplo n.º 3
0
func TestThatItSendsStdErrAsErr(t *testing.T) {
	sink, err := NewSyslogSink("appId", "syslog://localhost:24631", testhelpers.Logger())
	assert.NoError(t, err)
	closeChan := make(chan Sink)
	go sink.Run(closeChan)
	logMessage, err := logmessage.ParseMessage(testhelpers.MarshalledErrorLogMessage(t, "err", "appId"))
	assert.NoError(t, err)
	sink.Channel() <- logMessage
	data := <-dataReadChannel
	assert.Contains(t, string(data), "<3>")
	assert.Contains(t, string(data), "appId")
	assert.Contains(t, string(data), "err")
}
func TestConnectWithRetry(t *testing.T) {
	w := &writer{
		appId:                "appId",
		network:              "tcp",
		raddr:                "localhost:3456",
		getNextSleepDuration: newSimpleRetryStrategy(),
		logger:               testhelpers.Logger(),
	}

	err := w.connectWithRetry(0)
	assert.Error(t, err, "Exceeded maximum wait time for establishing a connection to write to.")

	err = w.connectWithRetry(15)
	assert.Error(t, err, "Exceeded maximum wait time for establishing a connection to write to.")

	err = w.connectWithRetry(-20)
	assert.Error(t, err, "Exceeded maximum wait time for establishing a connection to write to.")
}