1
0
mirror of https://github.com/aquasecurity/kube-bench.git synced 2024-12-23 23:18:33 +00:00
kube-bench/check/controls_test.go

41 lines
854 B
Go
Raw Normal View History

2017-06-23 11:05:07 +00:00
package check
import (
"io/ioutil"
"os"
"path/filepath"
2017-06-23 11:05:07 +00:00
"testing"
yaml "gopkg.in/yaml.v2"
)
const cfgDir = "../cfg/"
// validate that the files we're shipping are valid YAML
func TestYamlFiles(t *testing.T) {
err := filepath.Walk(cfgDir, func(path string, info os.FileInfo, err error) error {
2017-06-23 11:05:07 +00:00
if err != nil {
t.Fatalf("failure accessing path %q: %v\n", path, err)
2017-06-23 11:05:07 +00:00
}
if !info.IsDir() {
t.Logf("reading file: %s", path)
in, err := ioutil.ReadFile(path)
if err != nil {
t.Fatalf("error opening file %s: %v", path, err)
}
c := new(Controls)
err = yaml.Unmarshal(in, c)
if err == nil {
t.Logf("YAML file successfully unmarshalled: %s", path)
} else {
t.Fatalf("failed to load YAML from %s: %v", path, err)
}
2017-06-23 11:05:07 +00:00
}
return nil
})
if err != nil {
t.Fatalf("failure walking cfg dir: %v\n", err)
2017-06-23 11:05:07 +00:00
}
}