-
Notifications
You must be signed in to change notification settings - Fork 38
/
yaml_resource_loader_test.go
33 lines (30 loc) · 1.32 KB
/
yaml_resource_loader_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
package linter
import (
"bytes"
"github.com/stretchr/testify/assert"
"testing"
)
func TestYAMLLinterValidate(t *testing.T) {
options := Options{
Tags: []string{},
RuleIDs: []string{},
}
ruleSet := loadRulesForTest("./testdata/rules/generic-yaml.yml", t)
filenames := []string{"./testdata/resources/generic.config"}
loader := YAMLResourceLoader{Resources: ruleSet.Resources}
linter := FileLinter{Filenames: filenames, ValueSource: TestingValueSource{}, Loader: loader}
report, err := linter.Validate(ruleSet, options)
assert.Nil(t, err, "Expecting Validate to run without error")
assert.Equal(t, 17, len(report.ResourcesScanned), "Expecting Validate to scan 17 resources")
assert.Equal(t, 1, len(report.FilesScanned), "Expecting Validate to scan 1 file")
assert.Equal(t, 3, len(report.Violations), "Expecting Validate to find 3 violations")
}
func TestYAMLLinterSearch(t *testing.T) {
ruleSet := loadRulesForTest("./testdata/rules/generic-yaml.yml", t)
filenames := []string{"./testdata/resources/generic.config"}
loader := YAMLResourceLoader{Resources: ruleSet.Resources}
linter := FileLinter{Filenames: filenames, ValueSource: TestingValueSource{}, Loader: loader}
var b bytes.Buffer
linter.Search(ruleSet, "name", &b)
assert.Contains(t, b.String(), "gadget", "Expecting TestYAMLLinterSearch to find string in output")
}