Skip to content

Commit 37c593c

Browse files
committed
Add a test case for multiple input files
1 parent 4e6dfc1 commit 37c593c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

linter/linter_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,40 @@ func runTest(t *testing.T, test *linterTest, changedGoldensList *ChangedGoldensL
7272
}
7373
}
7474

75+
func runTests(t *testing.T, tests []*linterTest) {
76+
read := func(file string) []byte {
77+
bytz, err := ioutil.ReadFile(file)
78+
if err != nil {
79+
t.Fatalf("reading file: %s: %v", file, err)
80+
}
81+
return bytz
82+
}
83+
84+
vm := jsonnet.MakeVM()
85+
86+
var snippets []Snippet
87+
88+
for _, test := range tests {
89+
input := read(test.input)
90+
91+
snippets = append(snippets, Snippet{FileName: test.name, Code: string(input)})
92+
}
93+
94+
var outBuilder strings.Builder
95+
96+
errorsFound := LintSnippet(vm, &outBuilder, snippets)
97+
98+
outData := outBuilder.String()
99+
100+
if outData == "" && errorsFound {
101+
t.Error(fmt.Errorf("return value indicates problems present, but no output was produced"))
102+
}
103+
104+
if outData != "" && !errorsFound {
105+
t.Error(fmt.Errorf("return value indicates no problems, but output is not empty:\n%v", outData))
106+
}
107+
}
108+
75109
func TestLinter(t *testing.T) {
76110
flag.Parse()
77111

@@ -122,4 +156,8 @@ func TestLinter(t *testing.T) {
122156
t.Fail()
123157
})
124158
}
159+
160+
t.Run("passing multiple input files", func(t *testing.T) {
161+
runTests(t, tests)
162+
})
125163
}

0 commit comments

Comments
 (0)