Пример #1
0
func testRoundTripAndTextMarshaller(t *testing.T, f func(protolion.Logger), expected string) {
	for _, marshalPair := range []struct {
		marshaller   lion.Marshaller
		unmarshaller lion.Unmarshaller
	}{
		{
			protolion.DelimitedMarshaller,
			protolion.DelimitedUnmarshaller,
		},
		{
			protolion.Base64DelimitedMarshaller,
			protolion.Base64DelimitedUnmarshaller,
		},
	} {
		buffer := bytes.NewBuffer(nil)
		fakeTimer := newFakeTimer(0)
		logger := protolion.NewLogger(
			lion.NewLogger(
				lion.NewWritePusher(
					buffer,
					marshalPair.marshaller,
				),
				lion.LoggerWithIDAllocator(newFakeIDAllocator()),
				lion.LoggerWithTimer(fakeTimer),
			),
		)
		f(logger)
		puller := lion.NewReadPuller(
			buffer,
			marshalPair.unmarshaller,
		)
		writeBuffer := bytes.NewBuffer(nil)
		writePusher := lion.NewTextWritePusher(
			writeBuffer,
			lion.TextMarshallerDisableTime(),
		)
		for encodedEntry, pullErr := puller.Pull(); pullErr != io.EOF; encodedEntry, pullErr = puller.Pull() {
			require.NoError(t, pullErr)
			entry, err := encodedEntry.Decode()
			require.NoError(t, err)
			require.NoError(t, writePusher.Push(entry))
		}
		require.Equal(t, expected, writeBuffer.String())
	}
}
Пример #2
0
func testRoundTripAndTextMarshallerTail(t *testing.T, f func(protolion.Logger), expected string) {
	file, err := ioutil.TempFile("", "lion")
	require.NoError(t, err)
	filePath := file.Name()
	// will not actually get called if a require statement is hit
	defer func() {
		_ = file.Close()
		_ = os.Remove(filePath)

	}()
	fakeTimer := newFakeTimer(0)
	logger := protolion.NewLogger(
		lion.NewLogger(
			lion.NewWritePusher(
				file,
				protolion.Base64DelimitedNewlineMarshaller,
			),
			lion.LoggerWithIDAllocator(newFakeIDAllocator()),
			lion.LoggerWithTimer(fakeTimer),
		),
	)
	f(logger)
	writeBuffer := bytes.NewBuffer(nil)
	writePusher := lion.NewTextWritePusher(
		writeBuffer,
		lion.TextMarshallerDisableTime(),
	)
	require.NoError(
		t,
		taillion.Tail(
			filePath,
			protolion.Base64DelimitedUnmarshaller,
			writePusher.Push,
			nil,
			taillion.TailOptions{},
		),
	)
	require.Equal(t, expected, writeBuffer.String())
}