fix(inputs.tail): change test default watch method to poll when Win
This commit is contained in:
parent
a3454be2d8
commit
cfd50de57c
|
|
@ -450,89 +450,86 @@ func TestCharacterEncoding(t *testing.T) {
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watchMethod := defaultWatchMethod
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
watchMethod = "poll"
|
||||||
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
plugin *Tail
|
testfiles string
|
||||||
offset int64
|
fromBeginning bool
|
||||||
expected []telegraf.Metric
|
characterEncoding string
|
||||||
|
offset int64
|
||||||
|
expected []telegraf.Metric
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "utf-8",
|
name: "utf-8",
|
||||||
plugin: &Tail{
|
testfiles: "cpu-utf-8.influx",
|
||||||
Files: []string{filepath.Join(testdataDir, "cpu-utf-8.influx")},
|
fromBeginning: true,
|
||||||
FromBeginning: true,
|
characterEncoding: "utf-8",
|
||||||
MaxUndeliveredLines: 1000,
|
expected: full,
|
||||||
Log: testutil.Logger{},
|
|
||||||
CharacterEncoding: "utf-8",
|
|
||||||
},
|
|
||||||
expected: full,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "utf-8 seek",
|
name: "utf-8 seek",
|
||||||
plugin: &Tail{
|
testfiles: "cpu-utf-8.influx",
|
||||||
Files: []string{filepath.Join(testdataDir, "cpu-utf-8.influx")},
|
characterEncoding: "utf-8",
|
||||||
MaxUndeliveredLines: 1000,
|
offset: 0x33,
|
||||||
Log: testutil.Logger{},
|
expected: full[1:],
|
||||||
CharacterEncoding: "utf-8",
|
|
||||||
},
|
|
||||||
offset: 0x33,
|
|
||||||
expected: full[1:],
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "utf-16le",
|
name: "utf-16le",
|
||||||
plugin: &Tail{
|
testfiles: "cpu-utf-16le.influx",
|
||||||
Files: []string{filepath.Join(testdataDir, "cpu-utf-16le.influx")},
|
fromBeginning: true,
|
||||||
FromBeginning: true,
|
characterEncoding: "utf-16le",
|
||||||
MaxUndeliveredLines: 1000,
|
expected: full,
|
||||||
Log: testutil.Logger{},
|
|
||||||
CharacterEncoding: "utf-16le",
|
|
||||||
},
|
|
||||||
expected: full,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "utf-16le seek",
|
name: "utf-16le seek",
|
||||||
plugin: &Tail{
|
testfiles: "cpu-utf-16le.influx",
|
||||||
Files: []string{filepath.Join(testdataDir, "cpu-utf-16le.influx")},
|
characterEncoding: "utf-16le",
|
||||||
MaxUndeliveredLines: 1000,
|
offset: 0x68,
|
||||||
Log: testutil.Logger{},
|
expected: full[1:],
|
||||||
CharacterEncoding: "utf-16le",
|
|
||||||
},
|
|
||||||
offset: 0x68,
|
|
||||||
expected: full[1:],
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "utf-16be",
|
name: "utf-16be",
|
||||||
plugin: &Tail{
|
testfiles: "cpu-utf-16be.influx",
|
||||||
Files: []string{filepath.Join(testdataDir, "cpu-utf-16be.influx")},
|
fromBeginning: true,
|
||||||
FromBeginning: true,
|
characterEncoding: "utf-16be",
|
||||||
MaxUndeliveredLines: 1000,
|
expected: full,
|
||||||
Log: testutil.Logger{},
|
|
||||||
CharacterEncoding: "utf-16be",
|
|
||||||
},
|
|
||||||
expected: full,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
tt.plugin.SetParserFunc(func() (parsers.Parser, error) {
|
|
||||||
|
plugin := &Tail{
|
||||||
|
Files: []string{filepath.Join(testdataDir, tt.testfiles)},
|
||||||
|
FromBeginning: tt.fromBeginning,
|
||||||
|
MaxUndeliveredLines: 1000,
|
||||||
|
Log: testutil.Logger{},
|
||||||
|
CharacterEncoding: tt.characterEncoding,
|
||||||
|
WatchMethod: watchMethod,
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.SetParserFunc(func() (parsers.Parser, error) {
|
||||||
handler := influx.NewMetricHandler()
|
handler := influx.NewMetricHandler()
|
||||||
return influx.NewParser(handler), nil
|
return influx.NewParser(handler), nil
|
||||||
})
|
})
|
||||||
|
|
||||||
if tt.offset != 0 {
|
if tt.offset != 0 {
|
||||||
tt.plugin.offsets = map[string]int64{
|
plugin.offsets = map[string]int64{
|
||||||
tt.plugin.Files[0]: tt.offset,
|
plugin.Files[0]: tt.offset,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := tt.plugin.Init()
|
err := plugin.Init()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
err = tt.plugin.Start(&acc)
|
err = plugin.Start(&acc)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
acc.Wait(len(tt.expected))
|
acc.Wait(len(tt.expected))
|
||||||
tt.plugin.Stop()
|
plugin.Stop()
|
||||||
|
|
||||||
actual := acc.GetTelegrafMetrics()
|
actual := acc.GetTelegrafMetrics()
|
||||||
for _, m := range actual {
|
for _, m := range actual {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue