@@ -23,15 +23,8 @@ import (
23
23
"github.com/aws/cluster-api-provider-cloudstack/test/dummies"
24
24
. "github.com/onsi/ginkgo"
25
25
. "github.com/onsi/gomega"
26
- "github.com/onsi/gomega/types"
27
26
)
28
27
29
- var errString = func (err error ) string { return err .Error () }
30
-
31
- func BeErrorAndMatchRegexp (regexp string , args ... interface {}) types.GomegaMatcher {
32
- return SatisfyAll (HaveOccurred (), WithTransform (errString , MatchRegexp (regexp , args )))
33
- }
34
-
35
28
var _ = Describe ("CloudStackCluster webhooks" , func () {
36
29
var ctx context.Context
37
30
forbiddenRegex := "admission webhook.*denied the request.*Forbidden\\ : %s"
@@ -51,18 +44,19 @@ var _ = Describe("CloudStackCluster webhooks", func() {
51
44
52
45
It ("Should reject a CloudStackCluster with missing Zones.Network attribute" , func () {
53
46
dummies .CSCluster .Spec .Zones = []infrav1.Zone {{Name : "ZoneWNoNetwork" }}
54
- Ω (k8sClient .Create (ctx , dummies .CSCluster ). Error () ).Should (
55
- MatchRegexp (requiredRegex , "each Zone requires a Network specification" ))
47
+ Ω (k8sClient .Create (ctx , dummies .CSCluster )).Should (
48
+ MatchError ( MatchRegexp (requiredRegex , "each Zone requires a Network specification" ) ))
56
49
})
57
50
58
51
It ("Should reject a CloudStackCluster with missing Zones attribute" , func () {
59
52
dummies .CSCluster .Spec .Zones = []infrav1.Zone {}
60
- Ω (k8sClient .Create (ctx , dummies .CSCluster ). Error ()) .Should (MatchRegexp (requiredRegex , "Zones" ))
53
+ Ω (k8sClient .Create (ctx , dummies .CSCluster )) .Should (MatchError ( MatchRegexp (requiredRegex , "Zones" ) ))
61
54
})
62
55
63
56
It ("Should reject a CloudStackCluster with IdentityRef not of kind 'Secret'" , func () {
64
57
dummies .CSCluster .Spec .IdentityRef .Kind = "ConfigMap"
65
- Ω (k8sClient .Create (ctx , dummies .CSCluster ).Error ()).Should (MatchRegexp (forbiddenRegex , "must be a Secret" ))
58
+ Ω (k8sClient .Create (ctx , dummies .CSCluster )).
59
+ Should (MatchError (MatchRegexp (forbiddenRegex , "must be a Secret" )))
66
60
})
67
61
})
68
62
@@ -73,32 +67,32 @@ var _ = Describe("CloudStackCluster webhooks", func() {
73
67
74
68
It ("Should reject updates to CloudStackCluster Zones" , func () {
75
69
dummies .CSCluster .Spec .Zones = []infrav1.Zone {dummies .Zone1 }
76
- Ω (k8sClient .Update (ctx , dummies .CSCluster )).Should (BeErrorAndMatchRegexp ( forbiddenRegex , "Zones and sub" ))
70
+ Ω (k8sClient .Update (ctx , dummies .CSCluster )).Should (MatchError ( MatchRegexp ( forbiddenRegex , "Zones and sub" ) ))
77
71
})
78
72
It ("Should reject updates to CloudStackCluster Zones" , func () {
79
73
dummies .CSCluster .Spec .Zones [0 ].Network .Name = "ArbitraryUpdateNetworkName"
80
- Ω (k8sClient .Update (ctx , dummies .CSCluster )).Should (BeErrorAndMatchRegexp ( forbiddenRegex , "Zones and sub" ))
74
+ Ω (k8sClient .Update (ctx , dummies .CSCluster )).Should (MatchError ( MatchRegexp ( forbiddenRegex , "Zones and sub" ) ))
81
75
})
82
76
It ("Should reject updates to CloudStackCluster controlplaneendpoint.host" , func () {
83
77
dummies .CSCluster .Spec .ControlPlaneEndpoint .Host = "1.1.1.1"
84
78
Ω (k8sClient .Update (ctx , dummies .CSCluster )).
85
- Should (BeErrorAndMatchRegexp ( forbiddenRegex , "controlplaneendpoint\\ .host" ))
79
+ Should (MatchError ( MatchRegexp ( forbiddenRegex , "controlplaneendpoint\\ .host" ) ))
86
80
})
87
81
88
82
It ("Should reject updates to CloudStackCluster controlplaneendpoint.port" , func () {
89
83
dummies .CSCluster .Spec .ControlPlaneEndpoint .Port = int32 (1234 )
90
84
Ω (k8sClient .Update (ctx , dummies .CSCluster )).
91
- Should (BeErrorAndMatchRegexp ( forbiddenRegex , "controlplaneendpoint\\ .port" ))
85
+ Should (MatchError ( MatchRegexp ( forbiddenRegex , "controlplaneendpoint\\ .port" ) ))
92
86
})
93
87
It ("Should reject updates to the CloudStackCluster identity reference kind" , func () {
94
88
dummies .CSCluster .Spec .IdentityRef .Kind = "ConfigMap"
95
89
Ω (k8sClient .Update (ctx , dummies .CSCluster )).
96
- Should (BeErrorAndMatchRegexp ( forbiddenRegex , "identityRef \\ .Kind" ))
90
+ Should (MatchError ( MatchRegexp ( forbiddenRegex , "identityref \\ .kind" ) ))
97
91
})
98
92
It ("Should reject updates to the CloudStackCluster identity reference name" , func () {
99
93
dummies .CSCluster .Spec .IdentityRef .Name = "ConfigMap"
100
94
Ω (k8sClient .Update (ctx , dummies .CSCluster )).
101
- Should (BeErrorAndMatchRegexp ( forbiddenRegex , "identityRef \\ .name" ))
95
+ Should (MatchError ( MatchRegexp ( forbiddenRegex , "identityref \\ .name" ) ))
102
96
})
103
97
})
104
98
})
0 commit comments