Get Tail tests to pass on windows (#8927)
* fix tests * Update tail_test.go
This commit is contained in:
parent
d85a3637d5
commit
cfc5300ee2
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -25,6 +26,27 @@ var (
|
||||||
testdataDir = getTestdataDir()
|
testdataDir = getTestdataDir()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func NewTestTail() *Tail {
|
||||||
|
offsetsMutex.Lock()
|
||||||
|
offsetsCopy := make(map[string]int64, len(offsets))
|
||||||
|
for k, v := range offsets {
|
||||||
|
offsetsCopy[k] = v
|
||||||
|
}
|
||||||
|
offsetsMutex.Unlock()
|
||||||
|
watchMethod := defaultWatchMethod
|
||||||
|
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
watchMethod = "poll"
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Tail{
|
||||||
|
FromBeginning: false,
|
||||||
|
MaxUndeliveredLines: 1000,
|
||||||
|
offsets: offsetsCopy,
|
||||||
|
WatchMethod: watchMethod,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestTailBadLine(t *testing.T) {
|
func TestTailBadLine(t *testing.T) {
|
||||||
tmpfile, err := ioutil.TempFile("", "")
|
tmpfile, err := ioutil.TempFile("", "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -42,7 +64,7 @@ func TestTailBadLine(t *testing.T) {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
log.SetOutput(buf)
|
log.SetOutput(buf)
|
||||||
|
|
||||||
tt := NewTail()
|
tt := NewTestTail()
|
||||||
tt.Log = testutil.Logger{}
|
tt.Log = testutil.Logger{}
|
||||||
tt.FromBeginning = true
|
tt.FromBeginning = true
|
||||||
tt.Files = []string{tmpfile.Name()}
|
tt.Files = []string{tmpfile.Name()}
|
||||||
|
|
@ -70,7 +92,7 @@ func TestTailDosLineEndings(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tmpfile.Close()
|
tmpfile.Close()
|
||||||
|
|
||||||
tt := NewTail()
|
tt := NewTestTail()
|
||||||
tt.Log = testutil.Logger{}
|
tt.Log = testutil.Logger{}
|
||||||
tt.FromBeginning = true
|
tt.FromBeginning = true
|
||||||
tt.Files = []string{tmpfile.Name()}
|
tt.Files = []string{tmpfile.Name()}
|
||||||
|
|
@ -99,7 +121,7 @@ func TestGrokParseLogFilesWithMultiline(t *testing.T) {
|
||||||
//we make sure the timeout won't kick in
|
//we make sure the timeout won't kick in
|
||||||
duration, _ := time.ParseDuration("100s")
|
duration, _ := time.ParseDuration("100s")
|
||||||
|
|
||||||
tt := NewTail()
|
tt := NewTestTail()
|
||||||
tt.Log = testutil.Logger{}
|
tt.Log = testutil.Logger{}
|
||||||
tt.FromBeginning = true
|
tt.FromBeginning = true
|
||||||
tt.Files = []string{filepath.Join(testdataDir, "test_multiline.log")}
|
tt.Files = []string{filepath.Join(testdataDir, "test_multiline.log")}
|
||||||
|
|
@ -162,7 +184,7 @@ func TestGrokParseLogFilesWithMultilineTimeout(t *testing.T) {
|
||||||
// set tight timeout for tests
|
// set tight timeout for tests
|
||||||
duration := 10 * time.Millisecond
|
duration := 10 * time.Millisecond
|
||||||
|
|
||||||
tt := NewTail()
|
tt := NewTestTail()
|
||||||
tt.Log = testutil.Logger{}
|
tt.Log = testutil.Logger{}
|
||||||
tt.FromBeginning = true
|
tt.FromBeginning = true
|
||||||
tt.Files = []string{tmpfile.Name()}
|
tt.Files = []string{tmpfile.Name()}
|
||||||
|
|
@ -215,7 +237,7 @@ func TestGrokParseLogFilesWithMultilineTailerCloseFlushesMultilineBuffer(t *test
|
||||||
//we make sure the timeout won't kick in
|
//we make sure the timeout won't kick in
|
||||||
duration := 100 * time.Second
|
duration := 100 * time.Second
|
||||||
|
|
||||||
tt := NewTail()
|
tt := NewTestTail()
|
||||||
tt.Log = testutil.Logger{}
|
tt.Log = testutil.Logger{}
|
||||||
tt.FromBeginning = true
|
tt.FromBeginning = true
|
||||||
tt.Files = []string{filepath.Join(testdataDir, "test_multiline.log")}
|
tt.Files = []string{filepath.Join(testdataDir, "test_multiline.log")}
|
||||||
|
|
@ -274,7 +296,7 @@ cpu,42
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tmpfile.Close()
|
tmpfile.Close()
|
||||||
|
|
||||||
plugin := NewTail()
|
plugin := NewTestTail()
|
||||||
plugin.Log = testutil.Logger{}
|
plugin.Log = testutil.Logger{}
|
||||||
plugin.FromBeginning = true
|
plugin.FromBeginning = true
|
||||||
plugin.Files = []string{tmpfile.Name()}
|
plugin.Files = []string{tmpfile.Name()}
|
||||||
|
|
@ -331,7 +353,7 @@ func TestMultipleMetricsOnFirstLine(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tmpfile.Close()
|
tmpfile.Close()
|
||||||
|
|
||||||
plugin := NewTail()
|
plugin := NewTestTail()
|
||||||
plugin.Log = testutil.Logger{}
|
plugin.Log = testutil.Logger{}
|
||||||
plugin.FromBeginning = true
|
plugin.FromBeginning = true
|
||||||
plugin.Files = []string{tmpfile.Name()}
|
plugin.Files = []string{tmpfile.Name()}
|
||||||
|
|
@ -528,7 +550,7 @@ func TestTailEOF(t *testing.T) {
|
||||||
err = tmpfile.Sync()
|
err = tmpfile.Sync()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
tt := NewTail()
|
tt := NewTestTail()
|
||||||
tt.Log = testutil.Logger{}
|
tt.Log = testutil.Logger{}
|
||||||
tt.FromBeginning = true
|
tt.FromBeginning = true
|
||||||
tt.Files = []string{tmpfile.Name()}
|
tt.Files = []string{tmpfile.Name()}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue