mirror of
https://github.com/aquasecurity/kube-bench.git
synced 2024-12-22 14:48:07 +00:00
Add test to validate the YAML files
This commit is contained in:
parent
b4237ccb73
commit
e8df4aa512
32
check/controls_test.go
Normal file
32
check/controls_test.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package check
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
yaml "gopkg.in/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
const cfgDir = "../cfg/"
|
||||||
|
|
||||||
|
// validate that the files we're shipping are valid YAML
|
||||||
|
func TestYamlFiles(t *testing.T) {
|
||||||
|
files, err := ioutil.ReadDir(cfgDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error reading %s directory: %v", cfgDir, err)
|
||||||
|
}
|
||||||
|
for _, file := range files {
|
||||||
|
fileName := file.Name()
|
||||||
|
in, err := ioutil.ReadFile(cfgDir + fileName)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error opening file %s: %v", fileName, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c := new(Controls)
|
||||||
|
|
||||||
|
err = yaml.Unmarshal(in, c)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to load YAML from %s: %v", fileName, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user