forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
56 lines (47 loc) · 1.14 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"bufio"
"io"
"log"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func TestCases(t *testing.T) {
// Silence the output
log.SetOutput(io.Discard)
// Get all directories in testdata
folders, err := os.ReadDir("testcases")
require.NoError(t, err)
for _, f := range folders {
// Only handle folders
if !f.IsDir() {
continue
}
configFilename := filepath.Join("testcases", f.Name(), "telegraf.conf")
expecedFilename := filepath.Join("testcases", f.Name(), "expected.tags")
t.Run(f.Name(), func(t *testing.T) {
// Read the expected output
file, err := os.Open(expecedFilename)
require.NoError(t, err)
defer file.Close()
var expected []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
expected = append(expected, scanner.Text())
}
require.NoError(t, scanner.Err())
// Configure the command
cfg := &cmdConfig{
dryrun: true,
quiet: true,
configFiles: []string{configFilename},
root: "../..",
}
actual, err := process(cfg)
require.NoError(t, err)
require.EqualValues(t, expected, actual)
})
}
}