Skip to content

Commit 2a149d7

Browse files
committed
add line location tests
1 parent ddbcc23 commit 2a149d7

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tail_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,66 @@ func TestLocationMiddle(t *testing.T) {
208208
tailTest.Cleanup(tail, true)
209209
}
210210

211+
func TestLineLocationFull(t *testing.T) {
212+
tailTest := NewTailTest("location-full", t)
213+
tailTest.CreateFile("test.txt", "hello\nworld\n")
214+
tail := tailTest.StartTail("test.txt", Config{Follow: true, LineLocation: nil})
215+
go tailTest.VerifyTailOutput(tail, []string{"hello", "world"}, false)
216+
217+
// Delete after a reasonable delay, to give tail sufficient time
218+
// to read all lines.
219+
<-time.After(100 * time.Millisecond)
220+
tailTest.RemoveFile("test.txt")
221+
tailTest.Cleanup(tail, true)
222+
}
223+
224+
func TestLineLocationFullDontFollow(t *testing.T) {
225+
tailTest := NewTailTest("location-full-dontfollow", t)
226+
tailTest.CreateFile("test.txt", "hello\nworld\n")
227+
tail := tailTest.StartTail("test.txt", Config{Follow: false, LineLocation: nil})
228+
go tailTest.VerifyTailOutput(tail, []string{"hello", "world"}, false)
229+
230+
// Add more data only after reasonable delay.
231+
<-time.After(100 * time.Millisecond)
232+
tailTest.AppendFile("test.txt", "more\ndata\n")
233+
<-time.After(100 * time.Millisecond)
234+
235+
tailTest.Cleanup(tail, true)
236+
}
237+
238+
func TestLineLocationEnd(t *testing.T) {
239+
tailTest := NewTailTest("location-end", t)
240+
tailTest.CreateFile("test.txt", "hello\nworld\n")
241+
tail := tailTest.StartTail("test.txt", Config{Follow: true, LineLocation: &SeekInfo{0, os.SEEK_END}})
242+
go tailTest.VerifyTailOutput(tail, []string{"more", "data"}, false)
243+
244+
<-time.After(100 * time.Millisecond)
245+
tailTest.AppendFile("test.txt", "more\ndata\n")
246+
247+
// Delete after a reasonable delay, to give tail sufficient time
248+
// to read all lines.
249+
<-time.After(100 * time.Millisecond)
250+
tailTest.RemoveFile("test.txt")
251+
tailTest.Cleanup(tail, true)
252+
}
253+
254+
func TestLineLocationMiddle(t *testing.T) {
255+
// Test reading from middle.
256+
tailTest := NewTailTest("location-middle", t)
257+
tailTest.CreateFile("test.txt", "hello\nworld\n")
258+
tail := tailTest.StartTail("test.txt", Config{Follow: true, LineLocation: &SeekInfo{-1, os.SEEK_END}})
259+
go tailTest.VerifyTailOutput(tail, []string{"world", "more", "data"}, false)
260+
261+
<-time.After(100 * time.Millisecond)
262+
tailTest.AppendFile("test.txt", "more\ndata\n")
263+
264+
// Delete after a reasonable delay, to give tail sufficient time
265+
// to read all lines.
266+
<-time.After(100 * time.Millisecond)
267+
tailTest.RemoveFile("test.txt")
268+
tailTest.Cleanup(tail, true)
269+
}
270+
211271
// The use of polling file watcher could affect file rotation
212272
// (detected via renames), so test these explicitly.
213273

0 commit comments

Comments
 (0)