forked from Shopify/kubeaudit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix_test.go
54 lines (47 loc) · 1.31 KB
/
fix_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
package kubeaudit_test
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/Shopify/kubeaudit"
"github.com/Shopify/kubeaudit/auditors/all"
"github.com/Shopify/kubeaudit/config"
"github.com/Shopify/kubeaudit/internal/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// Test that fixing all fixtures in auditors/* results in manifests that pass all audits
func TestFix(t *testing.T) {
auditorDirs, err := ioutil.ReadDir("auditors")
if !assert.Nil(t, err) {
return
}
allAuditors, err := all.Auditors(config.KubeauditConfig{})
require.NoError(t, err)
for _, auditorDir := range auditorDirs {
if !auditorDir.IsDir() {
continue
}
fixturesDirPath := filepath.Join("..", auditorDir.Name(), "fixtures")
fixtureFiles, err := ioutil.ReadDir(fixturesDirPath)
if os.IsNotExist(err) {
continue
}
if !assert.Nil(t, err) {
return
}
for _, fixture := range fixtureFiles {
t.Run(filepath.Join(fixturesDirPath, fixture.Name()), func(t *testing.T) {
_, report := test.FixSetupMultiple(t, fixturesDirPath, fixture.Name(), allAuditors)
for _, result := range report.Results() {
for _, auditResult := range result.GetAuditResults() {
if !assert.NotEqual(t, kubeaudit.Error, auditResult.Severity) {
return
}
}
}
})
}
}
}