tests for the new Location spec
This commit is contained in:
parent
faf14146e7
commit
275e6442bd
30
tail_test.go
30
tail_test.go
|
@ -43,7 +43,7 @@ func TestMustExist(t *testing.T) {
|
||||||
func TestMaxLineSize(_t *testing.T) {
|
func TestMaxLineSize(_t *testing.T) {
|
||||||
t := NewTailTest("maxlinesize", _t)
|
t := NewTailTest("maxlinesize", _t)
|
||||||
t.CreateFile("test.txt", "hello\nworld\nfin\nhe")
|
t.CreateFile("test.txt", "hello\nworld\nfin\nhe")
|
||||||
tail := t.StartTail("test.txt", Config{Follow: true, Location: -1, MaxLineSize: 3})
|
tail := t.StartTail("test.txt", Config{Follow: true, Location: nil, MaxLineSize: 3})
|
||||||
go t.VerifyTailOutput(tail, []string{"hel", "lo", "wor", "ld", "fin", "he"})
|
go t.VerifyTailOutput(tail, []string{"hel", "lo", "wor", "ld", "fin", "he"})
|
||||||
|
|
||||||
// Delete after a reasonable delay, to give tail sufficient time
|
// Delete after a reasonable delay, to give tail sufficient time
|
||||||
|
@ -56,7 +56,7 @@ func TestMaxLineSize(_t *testing.T) {
|
||||||
func TestLocationFull(_t *testing.T) {
|
func TestLocationFull(_t *testing.T) {
|
||||||
t := NewTailTest("location-full", _t)
|
t := NewTailTest("location-full", _t)
|
||||||
t.CreateFile("test.txt", "hello\nworld\n")
|
t.CreateFile("test.txt", "hello\nworld\n")
|
||||||
tail := t.StartTail("test.txt", Config{Follow: true, Location: -1})
|
tail := t.StartTail("test.txt", Config{Follow: true, Location: nil})
|
||||||
go t.VerifyTailOutput(tail, []string{"hello", "world"})
|
go t.VerifyTailOutput(tail, []string{"hello", "world"})
|
||||||
|
|
||||||
// Delete after a reasonable delay, to give tail sufficient time
|
// Delete after a reasonable delay, to give tail sufficient time
|
||||||
|
@ -69,7 +69,7 @@ func TestLocationFull(_t *testing.T) {
|
||||||
func TestLocationFullDontFollow(_t *testing.T) {
|
func TestLocationFullDontFollow(_t *testing.T) {
|
||||||
t := NewTailTest("location-full-dontfollow", _t)
|
t := NewTailTest("location-full-dontfollow", _t)
|
||||||
t.CreateFile("test.txt", "hello\nworld\n")
|
t.CreateFile("test.txt", "hello\nworld\n")
|
||||||
tail := t.StartTail("test.txt", Config{Follow: false, Location: -1})
|
tail := t.StartTail("test.txt", Config{Follow: false, Location: nil})
|
||||||
go t.VerifyTailOutput(tail, []string{"hello", "world"})
|
go t.VerifyTailOutput(tail, []string{"hello", "world"})
|
||||||
|
|
||||||
// Add more data only after reasonable delay.
|
// Add more data only after reasonable delay.
|
||||||
|
@ -83,7 +83,7 @@ func TestLocationFullDontFollow(_t *testing.T) {
|
||||||
func TestLocationEnd(_t *testing.T) {
|
func TestLocationEnd(_t *testing.T) {
|
||||||
t := NewTailTest("location-end", _t)
|
t := NewTailTest("location-end", _t)
|
||||||
t.CreateFile("test.txt", "hello\nworld\n")
|
t.CreateFile("test.txt", "hello\nworld\n")
|
||||||
tail := t.StartTail("test.txt", Config{Follow: true, Location: 0})
|
tail := t.StartTail("test.txt", Config{Follow: true, Location: &SeekInfo{0, os.SEEK_END}})
|
||||||
go t.VerifyTailOutput(tail, []string{"more", "data"})
|
go t.VerifyTailOutput(tail, []string{"more", "data"})
|
||||||
|
|
||||||
<-time.After(100 * time.Millisecond)
|
<-time.After(100 * time.Millisecond)
|
||||||
|
@ -96,6 +96,23 @@ func TestLocationEnd(_t *testing.T) {
|
||||||
tail.Stop()
|
tail.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLocationMiddle(_t *testing.T) {
|
||||||
|
// Test reading from middle.
|
||||||
|
t := NewTailTest("location-end", _t)
|
||||||
|
t.CreateFile("test.txt", "hello\nworld\n")
|
||||||
|
tail := t.StartTail("test.txt", Config{Follow: true, Location: &SeekInfo{-6, os.SEEK_END}})
|
||||||
|
go t.VerifyTailOutput(tail, []string{"world", "more", "data"})
|
||||||
|
|
||||||
|
<-time.After(100 * time.Millisecond)
|
||||||
|
t.AppendFile("test.txt", "more\ndata\n")
|
||||||
|
|
||||||
|
// Delete after a reasonable delay, to give tail sufficient time
|
||||||
|
// to read all lines.
|
||||||
|
<-time.After(100 * time.Millisecond)
|
||||||
|
t.RemoveFile("test.txt")
|
||||||
|
tail.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
func _TestReOpen(_t *testing.T, poll bool) {
|
func _TestReOpen(_t *testing.T, poll bool) {
|
||||||
var name string
|
var name string
|
||||||
if poll {
|
if poll {
|
||||||
|
@ -107,7 +124,7 @@ func _TestReOpen(_t *testing.T, poll bool) {
|
||||||
t.CreateFile("test.txt", "hello\nworld\n")
|
t.CreateFile("test.txt", "hello\nworld\n")
|
||||||
tail := t.StartTail(
|
tail := t.StartTail(
|
||||||
"test.txt",
|
"test.txt",
|
||||||
Config{Follow: true, ReOpen: true, Poll: poll, Location: -1})
|
Config{Follow: true, ReOpen: true, Poll: poll})
|
||||||
|
|
||||||
go t.VerifyTailOutput(tail, []string{"hello", "world", "more", "data", "endofworld"})
|
go t.VerifyTailOutput(tail, []string{"hello", "world", "more", "data", "endofworld"})
|
||||||
|
|
||||||
|
@ -157,7 +174,7 @@ func _TestReSeek(_t *testing.T, poll bool) {
|
||||||
t.CreateFile("test.txt", "a really long string goes here\nhello\nworld\n")
|
t.CreateFile("test.txt", "a really long string goes here\nhello\nworld\n")
|
||||||
tail := t.StartTail(
|
tail := t.StartTail(
|
||||||
"test.txt",
|
"test.txt",
|
||||||
Config{Follow: true, ReOpen: false, Poll: poll, Location: -1})
|
Config{Follow: true, ReOpen: false, Poll: poll})
|
||||||
|
|
||||||
go t.VerifyTailOutput(tail, []string{
|
go t.VerifyTailOutput(tail, []string{
|
||||||
"a really long string goes here", "hello", "world", "h311o", "w0r1d", "endofworld"})
|
"a really long string goes here", "hello", "world", "h311o", "w0r1d", "endofworld"})
|
||||||
|
@ -193,7 +210,6 @@ func TestRateLimiting(_t *testing.T) {
|
||||||
t.CreateFile("test.txt", "hello\nworld\nagain\n")
|
t.CreateFile("test.txt", "hello\nworld\nagain\n")
|
||||||
config := Config{
|
config := Config{
|
||||||
Follow: true,
|
Follow: true,
|
||||||
Location: -1,
|
|
||||||
LimitRate: 2}
|
LimitRate: 2}
|
||||||
tail := t.StartTail("test.txt", config)
|
tail := t.StartTail("test.txt", config)
|
||||||
// TODO: also verify that tail resumes after the cooloff period.
|
// TODO: also verify that tail resumes after the cooloff period.
|
||||||
|
|
Loading…
Reference in New Issue