-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner_test.go
57 lines (48 loc) · 1.08 KB
/
runner_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
57
package conflint
import (
"bytes"
"fmt"
"path/filepath"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestRunner(t *testing.T) {
testcases := []struct {
dir string
out string
err string
}{
{
dir: "simple",
out: "app1/nginx.deploy.yaml:15:11: `privileged: true` is forbidden\n",
err: "found 1 linter error",
},
}
for i := range testcases {
tc := testcases[i]
t.Run(fmt.Sprintf(tc.dir), func(t *testing.T) {
buf := &bytes.Buffer{}
runner := &Runner{
Output: buf,
WorkDir: filepath.Join("testdata", tc.dir),
ConfigFile: "conflint.yaml",
Errformat: "%f:%l:%c: %m",
Delim: ": ",
}
err := runner.Run()
if err != nil {
if tc.err == "" {
t.Fatalf("unexpected error: %v", err)
} else if diff := cmp.Diff(tc.err, err.Error()); diff != "" {
t.Fatalf("unexpected error: %s", diff)
}
} else if tc.err != "" {
t.Fatalf("expected error: want %v, got none", tc.err)
}
out := buf.String()
if out != tc.out {
t.Errorf("unexpected output: want\n%s\n\ngot\n%s", tc.out, out)
}
})
}
}