-
Notifications
You must be signed in to change notification settings - Fork 141
/
scc_test.go
61 lines (50 loc) · 2 KB
/
scc_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
package reconcile_test
import (
"context"
security "github.com/openshift/api/security/v1"
"github.com/openshift/cluster-logging-operator/internal/reconcile"
"github.com/openshift/cluster-logging-operator/internal/runtime"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"github.com/google/go-cmp/cmp"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)
var _ = Describe("reconciling ", func() {
var (
anSCC = &security.SecurityContextConstraints{
TypeMeta: metav1.TypeMeta{
Kind: "SecurityContextConstraints",
APIVersion: security.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
},
ReadOnlyRootFilesystem: true,
}
)
var _ = DescribeTable("SCC", func(initial *security.SecurityContextConstraints, desired security.SecurityContextConstraints) {
globalScheme := scheme.Scheme
security.Install(globalScheme)
builder := fake.NewClientBuilder().WithScheme(globalScheme)
if initial != nil {
builder.WithRuntimeObjects(initial)
}
k8sClient := builder.Build()
Expect(reconcile.SecurityContextConstraints(k8sClient, &desired)).To(Succeed(), "Expect no error reconciling secrets")
key := client.ObjectKey{Name: desired.Name}
act := &security.SecurityContextConstraints{}
Expect(k8sClient.Get(context.TODO(), key, act)).To(Succeed(), "Exp. no error after reconciliation to try and verify")
act.ResourceVersion = "" //dont care here
desired.ResourceVersion = ""
Expect(cmp.Diff(act, &desired)).To(BeEmpty(), "Exp. the spec to be the same")
Expect(cmp.Diff(act, initial)).To(Not(BeEmpty()), "Exp. the spec to have been updated")
},
Entry("when it does not exist should create it", nil, *anSCC),
Entry("when spec is modified it should revert it", runtime.NewSCC("bar"), *anSCC),
Entry("when spec is not modified it should do nothing", anSCC, *anSCC),
)
})