Ejemplo n.º 1
0
// positionLogFile will update the internal read position of the logFile to be
// at the end of the file or somewhere in the middle if backlog has been specified.
func (stream *logStream) positionLogFile(logFile io.ReadSeeker) error {
	// Seek to the end, or lines back from the end if we need to.
	if !stream.fromTheStart {
		return tailer.SeekLastLines(logFile, stream.backlog, stream.filterLine)
	}
	return nil
}
Ejemplo n.º 2
0
func (s *tailerSuite) TestTailer(c *gc.C) {
	for i, test := range tests {
		c.Logf("Test #%d) %s", i, test.description)
		bufferSize := test.bufferSize
		if bufferSize == 0 {
			// Default value.
			bufferSize = 4096
		}
		s.PatchValue(tailer.BufferSize, bufferSize)
		reader, writer := io.Pipe()
		sigc := make(chan struct{}, 1)
		rs := startReadSeeker(c, test.data, test.initialLinesWritten, sigc)
		if !test.fromStart {
			err := tailer.SeekLastLines(rs, test.initialLinesRequested, test.filter)
			c.Assert(err, gc.IsNil)
		}
		tailer := tailer.NewTestTailer(rs, writer, test.filter, 2*time.Millisecond)
		linec := startReading(c, tailer, reader, writer)

		// Collect initial data.
		assertCollected(c, linec, test.initialCollectedData, nil)

		sigc <- struct{}{}

		// Collect remaining data, possibly with injection to stop
		// earlier or generate an error.
		var injection func([]string)
		if test.injector != nil {
			injection = test.injector(tailer, rs)
		}

		assertCollected(c, linec, test.appendedCollectedData, injection)

		if test.err == "" {
			c.Assert(tailer.Stop(), gc.IsNil)
		} else {
			c.Assert(tailer.Err(), gc.ErrorMatches, test.err)
		}
	}
}