Skip to content

Commit

Permalink
Close file to ensure it has been flushed (influxdata#7819)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored and idohalevi committed Sep 23, 2020
1 parent 672f710 commit 2b6e87d
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions plugins/inputs/tail/tail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestTailBadLine(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "")
require.NoError(t, err)
defer os.Remove(tmpfile.Name())
defer tmpfile.Close()

_, err = tmpfile.WriteString("cpu mytag= foo usage_idle= 100\n")
require.NoError(t, err)
Expand All @@ -31,6 +30,8 @@ func TestTailBadLine(t *testing.T) {
_, err = tmpfile.WriteString("cpu usage_idle=100\n")
require.NoError(t, err)

tmpfile.Close()

tt := NewTail()
tt.Log = testutil.Logger{}
tt.FromBeginning = true
Expand Down Expand Up @@ -58,9 +59,9 @@ func TestTailDosLineendings(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "")
require.NoError(t, err)
defer os.Remove(tmpfile.Name())
defer tmpfile.Close()
_, err = tmpfile.WriteString("cpu usage_idle=100\r\ncpu2 usage_idle=200\r\n")
require.NoError(t, err)
tmpfile.Close()

tt := NewTail()
tt.Log = testutil.Logger{}
Expand Down Expand Up @@ -91,17 +92,15 @@ func TestTailDosLineendings(t *testing.T) {
func TestCSVHeadersParsedOnce(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "")
require.NoError(t, err)
defer func() {
tmpfile.Close()
os.Remove(tmpfile.Name())
}()
defer os.Remove(tmpfile.Name())

_, err = tmpfile.WriteString(`
measurement,time_idle
cpu,42
cpu,42
`)
require.NoError(t, err)
tmpfile.Close()

plugin := NewTail()
plugin.Log = testutil.Logger{}
Expand Down Expand Up @@ -152,15 +151,13 @@ cpu,42
func TestMultipleMetricsOnFirstLine(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "")
require.NoError(t, err)
defer func() {
tmpfile.Close()
os.Remove(tmpfile.Name())
}()
defer os.Remove(tmpfile.Name())

_, err = tmpfile.WriteString(`
[{"time_idle": 42}, {"time_idle": 42}]
`)
require.NoError(t, err)
tmpfile.Close()

plugin := NewTail()
plugin.Log = testutil.Logger{}
Expand Down

0 comments on commit 2b6e87d

Please sign in to comment.