forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsa_test.go
40 lines (35 loc) · 976 Bytes
/
psa_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
package psa
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
k8sv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var _ = Describe("PSA", func() {
var (
privilegedNamespace *k8sv1.Namespace
restrictedNamespace *k8sv1.Namespace
)
BeforeEach(func() {
privilegedNamespace = newNamespace("privileged")
restrictedNamespace = newNamespace("restricted")
})
Context("should report correct PSA level", func() {
DescribeTable("when inspecting namespace", func(namespace *k8sv1.Namespace, privileged bool) {
Expect(IsNamespacePrivileged(namespace)).To(Equal(privileged))
},
Entry("privileged", privilegedNamespace, true),
Entry("restricted", restrictedNamespace, false),
Entry("with no label", &k8sv1.Namespace{}, false),
)
})
})
func newNamespace(level string) *k8sv1.Namespace {
return &k8sv1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
PSALabel: level,
},
},
}
}