@@ -19,86 +19,81 @@ package v1beta1_test
19
19
import (
20
20
"context"
21
21
22
- infrav1 "github.com/aws/cluster-api-provider-cloudstack/api/v1beta1"
23
22
"github.com/aws/cluster-api-provider-cloudstack/test/dummies"
24
23
. "github.com/onsi/ginkgo"
25
24
. "github.com/onsi/gomega"
26
25
)
27
26
28
27
var _ = Describe ("CloudStackMachineTemplate webhook" , func () {
29
28
var ctx context.Context
29
+ forbiddenRegex := "admission webhook.*denied the request.*Forbidden\\ : %s"
30
+ requiredRegex := "admission webhook.*denied the request.*Required value\\ : %s"
30
31
31
32
BeforeEach (func () { // Reset test vars to initial state.
32
33
dummies .SetDummyVars ()
33
34
ctx = context .Background ()
35
+ _ = k8sClient .Delete (ctx , dummies .CSMachineTemplate1 ) // Delete any remnants.
34
36
})
35
37
36
- Context ("When creating a CloudStackMachineTemplate with all attributes " , func () {
37
- It ("Should succeed " , func () {
38
+ Context ("When creating a CloudStackMachineTemplate" , func () {
39
+ It ("Should accept a CloudStackMachineTemplate with all attributes present " , func () {
38
40
Expect (k8sClient .Create (ctx , dummies .CSMachineTemplate1 )).Should (Succeed ())
39
41
})
40
- })
41
42
42
- Context ("When creating a CloudStackMachineTemplate with missing Offering attribute" , func () {
43
- It ("Should be rejected by the validating webhooks" , func () {
44
- dummies .CSMachine1 .Spec .Offering = ""
43
+ It ("Should reject a CloudStackMachineTemplate when missing the VM Offering attribute" , func () {
44
+ dummies .CSMachineTemplate1 .Spec .Spec .Spec .Offering = ""
45
45
Expect (k8sClient .Create (ctx , dummies .CSMachineTemplate1 ).Error ()).
46
- Should (MatchRegexp ("admission webhook.*denied the request.*Required value \\ : Offering" ))
46
+ Should (MatchRegexp (requiredRegex , " Offering" ))
47
47
})
48
- })
49
48
50
- Context ("When creating a CloudStackMachineTemplate with missing Template attribute" , func () {
51
- It ("Should be rejected by the validating webhooks" , func () {
52
- dummies .CSMachine1 .Spec .Template = ""
49
+ It ("Should reject a CloudStackMachineTemplate when missing the VM Template attribute" , func () {
50
+ dummies .CSMachineTemplate1 .Spec .Spec .Spec .Template = ""
53
51
Expect (k8sClient .Create (ctx , dummies .CSMachineTemplate1 ).Error ()).
54
- Should (MatchRegexp ("admission webhook.*denied the request.*Required value \\ : Template" ))
52
+ Should (MatchRegexp (requiredRegex , " Template" ))
55
53
})
56
- })
57
54
58
- Context ("When creating a CloudStackMachineTemplate with the wrong kind of IdentityReference" , func () {
59
- It ("Should be rejected by the validating webhooks" , func () {
55
+ It ("Should be reject a CloudStackMachineTemplate with IdentityRef not of kind 'Secret'" , func () {
60
56
dummies .CSMachine1 .Spec .IdentityRef .Kind = "ConfigMap"
61
57
Expect (k8sClient .Create (ctx , dummies .CSMachine1 ).Error ()).
62
- Should (MatchRegexp ("admission webhook.*denied the request.*Forbidden \\ : must be a Secret" ))
58
+ Should (MatchRegexp (forbiddenRegex , " must be a Secret" ))
63
59
})
64
60
})
65
61
66
62
Context ("When updating a CloudStackMachineTemplate" , func () {
67
- It ("Should be rejected by the machine template validating webhooks" , func () {
68
- Expect (k8sClient .Create (ctx , dummies .CSMachineTemplate1 )).Should (Succeed ())
69
-
70
- forbiddenRegex := "admission webhook.*denied the request.*Forbidden\\ : %s"
71
- cloudStackMachineTemplateUpdate := & infrav1.CloudStackMachineTemplate {}
63
+ BeforeEach (func () { // Reset test vars to initial state.
64
+ Ω (k8sClient .Create (ctx , dummies .CSMachineTemplate1 )).Should (Succeed ())
65
+ })
72
66
73
- dummies . CSMachineTemplate1 . DeepCopyInto ( cloudStackMachineTemplateUpdate )
74
- cloudStackMachineTemplateUpdate . Spec .Spec .Spec .Template = "Template2 "
75
- Expect (k8sClient .Update (ctx , cloudStackMachineTemplateUpdate ).Error ()).
76
- Should ( MatchRegexp ( forbiddenRegex , "template" ) )
67
+ It ( "should reject VM template updates to the CloudStackMachineTemplate" , func () {
68
+ dummies . CSMachineTemplate1 . Spec .Spec .Spec .Template = "ArbitraryUpdateTemplate "
69
+ Ω (k8sClient .Update (ctx , dummies . CSMachineTemplate1 ).Error ()).Should ( MatchRegexp ( forbiddenRegex , "template" ))
70
+ } )
77
71
78
- dummies . CSMachineTemplate1 . DeepCopyInto ( cloudStackMachineTemplateUpdate )
79
- cloudStackMachineTemplateUpdate .Spec .Spec .Spec .Offering = "Offering2"
80
- Expect (k8sClient .Update (ctx , cloudStackMachineTemplateUpdate ).Error ()).
81
- Should ( MatchRegexp ( forbiddenRegex , "offering" ) )
72
+ It ( "should reject VM offering updates to the CloudStackMachineTemplate" , func () {
73
+ dummies . CSMachineTemplate1 .Spec .Spec .Spec .Offering = "Offering2"
74
+ Ω (k8sClient .Update (ctx , dummies . CSMachineTemplate1 ).Error ()).Should ( MatchRegexp ( forbiddenRegex , "offering" ))
75
+ } )
82
76
83
- dummies . CSMachineTemplate1 . DeepCopyInto ( cloudStackMachineTemplateUpdate )
84
- cloudStackMachineTemplateUpdate .Spec .Spec .Spec .Details = map [string ]string {"memoryOvercommitRatio" : "1.5" }
85
- Expect (k8sClient .Update (ctx , cloudStackMachineTemplateUpdate ).Error ()).
86
- Should ( MatchRegexp ( forbiddenRegex , "details" ) )
77
+ It ( "should reject updates to VM details of the CloudStackMachineTemplate" , func () {
78
+ dummies . CSMachineTemplate1 .Spec .Spec .Spec .Details = map [string ]string {"memoryOvercommitRatio" : "1.5" }
79
+ Ω (k8sClient .Update (ctx , dummies . CSMachineTemplate1 ).Error ()).Should ( MatchRegexp ( forbiddenRegex , "details" ))
80
+ } )
87
81
88
- dummies . CSMachineTemplate1 . DeepCopyInto ( cloudStackMachineTemplateUpdate )
89
- cloudStackMachineTemplateUpdate .Spec .Spec .Spec .IdentityRef .Kind = "configMap"
90
- Expect (k8sClient .Update (ctx , cloudStackMachineTemplateUpdate ).Error ()).
82
+ It ( "should reject identity reference kind updates to the CloudStackMachineTemplate" , func () {
83
+ dummies . CSMachineTemplate1 .Spec .Spec .Spec .IdentityRef .Kind = "configMap"
84
+ Ω (k8sClient .Update (ctx , dummies . CSMachineTemplate1 ).Error ()).
91
85
Should (MatchRegexp (forbiddenRegex , "identityRef\\ .Kind" ))
86
+ })
92
87
93
- dummies . CSMachineTemplate1 . DeepCopyInto ( cloudStackMachineTemplateUpdate )
94
- cloudStackMachineTemplateUpdate .Spec .Spec .Spec .IdentityRef .Name = "IDentityConfigMap"
95
- Expect (k8sClient .Update (ctx , cloudStackMachineTemplateUpdate ).Error ()).
88
+ It ( "should reject identity reference name updates to the CloudStackMachineTemplate" , func () {
89
+ dummies . CSMachineTemplate1 .Spec .Spec .Spec .IdentityRef .Name = "IDentityConfigMap"
90
+ Ω (k8sClient .Update (ctx , dummies . CSMachineTemplate1 ).Error ()).
96
91
Should (MatchRegexp (forbiddenRegex , "identityRef\\ .Name" ))
92
+ })
97
93
98
- dummies .CSMachineTemplate1 .DeepCopyInto (cloudStackMachineTemplateUpdate )
99
- cloudStackMachineTemplateUpdate .Spec .Spec .Spec .AffinityGroupIDs = []string {"28b907b8-75a7-4214-bd3d-6c61961fc2ag" }
100
- Expect (k8sClient .Update (ctx , cloudStackMachineTemplateUpdate )).
101
- ShouldNot (Succeed ())
94
+ It ("should reject updates to the list of AffinityGroupIDs of the CloudStackMachineTemplate" , func () {
95
+ dummies .CSMachineTemplate1 .Spec .Spec .Spec .AffinityGroupIDs = []string {"28b907b8-75a7-4214-bd3d-6c61961fc2ag" }
96
+ Ω (k8sClient .Update (ctx , dummies .CSMachineTemplate1 )).ShouldNot (Succeed ())
102
97
})
103
98
})
104
99
})
0 commit comments