forked from Shopify/kubeaudit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubeaudit_test.go
84 lines (63 loc) · 2.09 KB
/
kubeaudit_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package kubeaudit_test
import (
"testing"
"github.com/Shopify/kubeaudit"
"github.com/Shopify/kubeaudit/auditors/all"
"github.com/Shopify/kubeaudit/config"
"github.com/Shopify/kubeaudit/internal/k8sinternal"
"github.com/Shopify/kubeaudit/internal/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNew(t *testing.T) {
require := require.New(t)
allAuditors, err := all.Auditors(config.KubeauditConfig{})
require.NoError(err)
auditor, err := kubeaudit.New(allAuditors)
require.NoError(err)
assert.NotNil(t, auditor)
_, err = kubeaudit.New(nil)
require.NotNil(err)
}
func TestAuditLocal(t *testing.T) {
if !test.UseKind() {
return
}
require := require.New(t)
allAuditors, err := all.Auditors(config.KubeauditConfig{})
require.NoError(err)
auditor, err := kubeaudit.New(allAuditors)
require.NoError(err)
_, err = auditor.AuditLocal("", "", k8sinternal.ClientOptions{})
require.NoError(err)
_, err = auditor.AuditLocal("invalid_path", "", k8sinternal.ClientOptions{})
require.NotNil(err)
_, err = auditor.AuditLocal("", "invalid_context", k8sinternal.ClientOptions{})
require.NotNil(err)
}
func TestAuditCluster(t *testing.T) {
require := require.New(t)
allAuditors, err := all.Auditors(config.KubeauditConfig{})
require.NoError(err)
auditor, err := kubeaudit.New(allAuditors)
require.NoError(err)
_, err = auditor.AuditCluster(k8sinternal.ClientOptions{})
require.NotNil(err)
}
func TestUnknownResource(t *testing.T) {
// Make sure we produce only warning results for resources kubeaudit doesn't know how to audit
files := []string{"unknown_resource_type.yml", "custom_resource_definition.yml"}
allAuditors, err := all.Auditors(config.KubeauditConfig{})
require.NoError(t, err)
for _, file := range files {
t.Run(file, func(t *testing.T) {
_, report := test.FixSetupMultiple(t, "internal/test/fixtures", file, allAuditors)
require.NotNil(t, report)
for _, result := range report.Results() {
for _, auditResult := range result.GetAuditResults() {
assert.Equal(t, kubeaudit.Warn, auditResult.Severity)
}
}
})
}
}