-
Notifications
You must be signed in to change notification settings - Fork 17
/
default_test.go
141 lines (114 loc) · 5.18 KB
/
default_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package controllers
import (
g "github.com/onsi/ginkgo/v2"
o "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/shipwright-io/operator/api/v1alpha1"
"github.com/shipwright-io/operator/test"
)
var _ = g.Describe("Reconcile default ShipwrightBuild installation", func() {
// targetNamespace namespace where shipwright Controller and dependencies will be located
const targetNamespace = "target-namespace"
// build Build instance employed during testing
var build *v1alpha1.ShipwrightBuild
baseClusterRole := &rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Name: "shipwright-build-controller",
},
}
baseClusterRoleBinding := &rbacv1.ClusterRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "shipwright-build-controller",
},
}
baseServiceAccount := &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Namespace: targetNamespace,
Name: "shipwright-build-controller",
},
}
baseDeployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Namespace: targetNamespace,
Name: "shipwright-build-controller",
},
}
g.BeforeEach(func(ctx g.SpecContext) {
// setting up the namespaces, where Shipwright Controller will be deployed
setupTektonCRDs(ctx)
build = createShipwrightBuild(ctx, targetNamespace)
})
g.AfterEach(func(ctx g.SpecContext) {
deleteShipwrightBuild(ctx, build)
g.By("checking that the shipwright-build-controller deployment has been removed")
deployment := baseDeployment.DeepCopy()
test.EventuallyRemoved(ctx, k8sClient, deployment)
})
g.When("a ShipwrightBuild object is created", func() {
g.It("creates RBAC for the Shipwright build controller", func(ctx g.SpecContext) {
expectedClusterRole := baseClusterRole.DeepCopy()
test.EventuallyExists(ctx, k8sClient, expectedClusterRole)
expectedClusterRoleBinding := baseClusterRoleBinding.DeepCopy()
test.EventuallyExists(ctx, k8sClient, expectedClusterRoleBinding)
expectedServiceAccount := baseServiceAccount.DeepCopy()
test.EventuallyExists(ctx, k8sClient, expectedServiceAccount)
})
g.It("creates a deployment for the Shipwright build controller", func(ctx g.SpecContext) {
expectedDeployment := baseDeployment.DeepCopy()
test.EventuallyExists(ctx, k8sClient, expectedDeployment)
})
g.It("creates custom resource definitions for the Shipwright build APIs", func(ctx g.SpecContext) {
test.CRDEventuallyExists(ctx, k8sClient, "builds.shipwright.io")
test.CRDEventuallyExists(ctx, k8sClient, "buildruns.shipwright.io")
test.CRDEventuallyExists(ctx, k8sClient, "buildstrategies.shipwright.io")
test.CRDEventuallyExists(ctx, k8sClient, "clusterbuildstrategies.shipwright.io")
})
})
g.When("a ShipwrightBuild object is deleted", func() {
g.It("deletes the RBAC for the Shipwright build controller", func(ctx g.SpecContext) {
expectedClusterRole := baseClusterRole.DeepCopy()
expectedClusterRoleBinding := baseClusterRoleBinding.DeepCopy()
expectedServiceAccount := baseServiceAccount.DeepCopy()
// Setup - ensure the objects we want exist
test.EventuallyExists(ctx, k8sClient, expectedClusterRole)
test.EventuallyExists(ctx, k8sClient, expectedClusterRoleBinding)
test.EventuallyExists(ctx, k8sClient, expectedServiceAccount)
// Test - delete the ShipwrightBuild instance
err := k8sClient.Delete(ctx, build, &client.DeleteOptions{})
o.Expect(err).NotTo(o.HaveOccurred())
// Verify - check the behavior
test.EventuallyRemoved(ctx, k8sClient, expectedClusterRole)
test.EventuallyRemoved(ctx, k8sClient, expectedClusterRoleBinding)
test.EventuallyRemoved(ctx, k8sClient, expectedServiceAccount)
})
g.It("deletes the deployment for the Shipwright build controller", func(ctx g.SpecContext) {
expectedDeployment := baseDeployment.DeepCopy()
// Setup - ensure the objects we want exist
test.EventuallyExists(ctx, k8sClient, expectedDeployment)
// Test - delete the ShipwrightBuild instance
err := k8sClient.Delete(ctx, build, &client.DeleteOptions{})
o.Expect(err).NotTo(o.HaveOccurred())
// Verify - check the behavior
test.EventuallyRemoved(ctx, k8sClient, expectedDeployment)
})
// Deteling the build instance should not delete CRDS
g.It("should not delete the custom resource definitions for the Shipwright build APIs", func(ctx g.SpecContext) {
test.CRDEventuallyExists(ctx, k8sClient, "builds.shipwright.io")
test.CRDEventuallyExists(ctx, k8sClient, "buildruns.shipwright.io")
test.CRDEventuallyExists(ctx, k8sClient, "buildstrategies.shipwright.io")
test.CRDEventuallyExists(ctx, k8sClient, "clusterbuildstrategies.shipwright.io")
// Test - delete the ShipwrightBuild instance
err := k8sClient.Delete(ctx, build, &client.DeleteOptions{})
o.Expect(err).NotTo(o.HaveOccurred())
// Verify - check the behavior
test.CRDEventuallyExists(ctx, k8sClient, "builds.shipwright.io")
test.CRDEventuallyExists(ctx, k8sClient, "buildruns.shipwright.io")
test.CRDEventuallyExists(ctx, k8sClient, "buildstrategies.shipwright.io")
test.CRDEventuallyExists(ctx, k8sClient, "clusterbuildstrategies.shipwright.io")
})
})
})