Skip to content

Commit

Permalink
Simplify tests using File.WriteString to use test helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaqx0r committed Feb 11, 2019
1 parent f8b404e commit b6d001c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
9 changes: 3 additions & 6 deletions internal/tailer/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ func TestReadPartial(t *testing.T) {
if f.partial.String() != "" {
t.Errorf("partial line not empty: %q", f.partial)
}
_, err = fd.WriteString("o")
testutil.FatalIfErr(t, err)
_, err = fd.WriteString("hi")
testutil.FatalIfErr(t, err)
testutil.WriteString(t, fd, "o")
testutil.WriteString(t, fd, "hi")
// memmapfs shares data structure here and in code under test so reset the file offset
_, err = fd.Seek(0, 0)
testutil.FatalIfErr(t, err)
Expand All @@ -66,8 +64,7 @@ func TestReadPartial(t *testing.T) {
// reset the cursor again
_, err = fd.Seek(3, io.SeekStart)
testutil.FatalIfErr(t, err)
_, err = fd.WriteString("\n")
testutil.FatalIfErr(t, err)
testutil.WriteString(t, fd, "\n")
_, err = fd.Seek(-1, io.SeekEnd)
testutil.FatalIfErr(t, err)
err = f.Read()
Expand Down
17 changes: 4 additions & 13 deletions internal/tailer/tail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ func TestHandleLogUpdate(t *testing.T) {
}

wg.Add(4)
_, err = f.WriteString("a\nb\nc\nd\n")
if err != nil {
t.Fatal(err)
}
testutil.WriteString(t, f, "a\nb\nc\nd\n")
// f.Seek(0, 0)
w.InjectUpdate(logfile)

Expand Down Expand Up @@ -183,26 +180,20 @@ func TestHandleLogUpdatePartialLine(t *testing.T) {
t.Fatal(err)
}

_, err = f.WriteString("a")
if err != nil {
t.Fatal(err)
}
testutil.WriteString(t, f, "a")
//f.Seek(0, 0)
w.InjectUpdate(logfile)

//f.Seek(1, 0)
_, err = f.WriteString("b")
testutil.WriteString(t, f, "b")
if err != nil {
t.Error(err)
}
// f.Seek(1, 0)
w.InjectUpdate(logfile)

//f.Seek(2, 0)
_, err = f.WriteString("\n")
if err != nil {
t.Error(err)
}
testutil.WriteString(t, f, "\n")
//f.Seek(2, 0)
w.InjectUpdate(logfile)

Expand Down

0 comments on commit b6d001c

Please sign in to comment.