@@ -37,18 +37,40 @@ import (
37
37
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
38
38
)
39
39
40
+ type testContext struct {}
41
+
42
+ // GetTLSKeyfile returns the keyfile encoded TLS certificate+key for
43
+ // the given member.
44
+ func (c * testContext ) GetTLSKeyfile (group api.ServerGroup , member api.MemberStatus ) (string , error ) {
45
+ return "" , maskAny (fmt .Errorf ("Not implemented" ))
46
+ }
47
+
48
+ // GetTLSCA returns the TLS CA certificate in the secret with given name.
49
+ // Returns: publicKey, privateKey, ownerByDeployment, error
50
+ func (c * testContext ) GetTLSCA (secretName string ) (string , string , bool , error ) {
51
+ return "" , "" , false , maskAny (fmt .Errorf ("Not implemented" ))
52
+ }
53
+
54
+ // CreateEvent creates a given event.
55
+ // On error, the error is logged.
56
+ func (c * testContext ) CreateEvent (evt * k8sutil.Event ) {
57
+ // not implemented
58
+ }
59
+
60
+ // GetPvc gets a PVC by the given name, in the samespace of the deployment.
61
+ func (c * testContext ) GetPvc (pvcName string ) (* v1.PersistentVolumeClaim , error ) {
62
+ return nil , maskAny (fmt .Errorf ("Not implemented" ))
63
+ }
64
+
65
+ // GetExpectedPodArguments creates command line arguments for a server in the given group with given ID.
66
+ func (c * testContext ) GetExpectedPodArguments (apiObject metav1.Object , deplSpec api.DeploymentSpec , group api.ServerGroup ,
67
+ agents api.MemberStatusList , id string ) []string {
68
+ return nil // not implemented
69
+ }
70
+
40
71
// TestCreatePlanSingleScale creates a `single` deployment to test the creating of scaling plan.
41
72
func TestCreatePlanSingleScale (t * testing.T ) {
42
- getTLSKeyfile := func (group api.ServerGroup , member api.MemberStatus ) (string , error ) {
43
- return "" , maskAny (fmt .Errorf ("Not implemented" ))
44
- }
45
- getTLSCA := func (string ) (string , string , bool , error ) {
46
- return "" , "" , false , maskAny (fmt .Errorf ("Not implemented" ))
47
- }
48
- getPVC := func (pvcName string ) (* v1.PersistentVolumeClaim , error ) {
49
- return nil , maskAny (fmt .Errorf ("Not implemented" ))
50
- }
51
- createEvent := func (evt * k8sutil.Event ) {}
73
+ c := & testContext {}
52
74
log := zerolog .Nop ()
53
75
spec := api.DeploymentSpec {
54
76
Mode : api .NewMode (api .DeploymentModeSingle ),
@@ -64,7 +86,7 @@ func TestCreatePlanSingleScale(t *testing.T) {
64
86
65
87
// Test with empty status
66
88
var status api.DeploymentStatus
67
- newPlan , changed := createPlan (log , depl , nil , spec , status , nil , getTLSKeyfile , getTLSCA , getPVC , createEvent )
89
+ newPlan , changed := createPlan (log , depl , nil , spec , status , nil , c )
68
90
assert .True (t , changed )
69
91
assert .Len (t , newPlan , 0 ) // Single mode does not scale
70
92
@@ -75,7 +97,7 @@ func TestCreatePlanSingleScale(t *testing.T) {
75
97
PodName : "something" ,
76
98
},
77
99
}
78
- newPlan , changed = createPlan (log , depl , nil , spec , status , nil , getTLSKeyfile , getTLSCA , getPVC , createEvent )
100
+ newPlan , changed = createPlan (log , depl , nil , spec , status , nil , c )
79
101
assert .True (t , changed )
80
102
assert .Len (t , newPlan , 0 ) // Single mode does not scale
81
103
@@ -90,23 +112,14 @@ func TestCreatePlanSingleScale(t *testing.T) {
90
112
PodName : "something1" ,
91
113
},
92
114
}
93
- newPlan , changed = createPlan (log , depl , nil , spec , status , nil , getTLSKeyfile , getTLSCA , getPVC , createEvent )
115
+ newPlan , changed = createPlan (log , depl , nil , spec , status , nil , c )
94
116
assert .True (t , changed )
95
117
assert .Len (t , newPlan , 0 ) // Single mode does not scale
96
118
}
97
119
98
120
// TestCreatePlanActiveFailoverScale creates a `ActiveFailover` deployment to test the creating of scaling plan.
99
121
func TestCreatePlanActiveFailoverScale (t * testing.T ) {
100
- getTLSKeyfile := func (group api.ServerGroup , member api.MemberStatus ) (string , error ) {
101
- return "" , maskAny (fmt .Errorf ("Not implemented" ))
102
- }
103
- getTLSCA := func (string ) (string , string , bool , error ) {
104
- return "" , "" , false , maskAny (fmt .Errorf ("Not implemented" ))
105
- }
106
- getPVC := func (pvcName string ) (* v1.PersistentVolumeClaim , error ) {
107
- return nil , maskAny (fmt .Errorf ("Not implemented" ))
108
- }
109
- createEvent := func (evt * k8sutil.Event ) {}
122
+ c := & testContext {}
110
123
log := zerolog .Nop ()
111
124
spec := api.DeploymentSpec {
112
125
Mode : api .NewMode (api .DeploymentModeActiveFailover ),
@@ -123,7 +136,7 @@ func TestCreatePlanActiveFailoverScale(t *testing.T) {
123
136
124
137
// Test with empty status
125
138
var status api.DeploymentStatus
126
- newPlan , changed := createPlan (log , depl , nil , spec , status , nil , getTLSKeyfile , getTLSCA , getPVC , createEvent )
139
+ newPlan , changed := createPlan (log , depl , nil , spec , status , nil , c )
127
140
assert .True (t , changed )
128
141
require .Len (t , newPlan , 2 )
129
142
assert .Equal (t , api .ActionTypeAddMember , newPlan [0 ].Type )
@@ -136,7 +149,7 @@ func TestCreatePlanActiveFailoverScale(t *testing.T) {
136
149
PodName : "something" ,
137
150
},
138
151
}
139
- newPlan , changed = createPlan (log , depl , nil , spec , status , nil , getTLSKeyfile , getTLSCA , getPVC , createEvent )
152
+ newPlan , changed = createPlan (log , depl , nil , spec , status , nil , c )
140
153
assert .True (t , changed )
141
154
require .Len (t , newPlan , 1 )
142
155
assert .Equal (t , api .ActionTypeAddMember , newPlan [0 ].Type )
@@ -161,7 +174,7 @@ func TestCreatePlanActiveFailoverScale(t *testing.T) {
161
174
PodName : "something4" ,
162
175
},
163
176
}
164
- newPlan , changed = createPlan (log , depl , nil , spec , status , nil , getTLSKeyfile , getTLSCA , getPVC , createEvent )
177
+ newPlan , changed = createPlan (log , depl , nil , spec , status , nil , c )
165
178
assert .True (t , changed )
166
179
require .Len (t , newPlan , 2 ) // Note: Downscaling is only down 1 at a time
167
180
assert .Equal (t , api .ActionTypeShutdownMember , newPlan [0 ].Type )
@@ -172,16 +185,7 @@ func TestCreatePlanActiveFailoverScale(t *testing.T) {
172
185
173
186
// TestCreatePlanClusterScale creates a `cluster` deployment to test the creating of scaling plan.
174
187
func TestCreatePlanClusterScale (t * testing.T ) {
175
- getTLSKeyfile := func (group api.ServerGroup , member api.MemberStatus ) (string , error ) {
176
- return "" , maskAny (fmt .Errorf ("Not implemented" ))
177
- }
178
- getTLSCA := func (string ) (string , string , bool , error ) {
179
- return "" , "" , false , maskAny (fmt .Errorf ("Not implemented" ))
180
- }
181
- getPVC := func (pvcName string ) (* v1.PersistentVolumeClaim , error ) {
182
- return nil , maskAny (fmt .Errorf ("Not implemented" ))
183
- }
184
- createEvent := func (evt * k8sutil.Event ) {}
188
+ c := & testContext {}
185
189
log := zerolog .Nop ()
186
190
spec := api.DeploymentSpec {
187
191
Mode : api .NewMode (api .DeploymentModeCluster ),
@@ -197,7 +201,7 @@ func TestCreatePlanClusterScale(t *testing.T) {
197
201
198
202
// Test with empty status
199
203
var status api.DeploymentStatus
200
- newPlan , changed := createPlan (log , depl , nil , spec , status , nil , getTLSKeyfile , getTLSCA , getPVC , createEvent )
204
+ newPlan , changed := createPlan (log , depl , nil , spec , status , nil , c )
201
205
assert .True (t , changed )
202
206
require .Len (t , newPlan , 6 ) // Adding 3 dbservers & 3 coordinators (note: agents do not scale now)
203
207
assert .Equal (t , api .ActionTypeAddMember , newPlan [0 ].Type )
@@ -230,7 +234,7 @@ func TestCreatePlanClusterScale(t *testing.T) {
230
234
PodName : "coordinator1" ,
231
235
},
232
236
}
233
- newPlan , changed = createPlan (log , depl , nil , spec , status , nil , getTLSKeyfile , getTLSCA , getPVC , createEvent )
237
+ newPlan , changed = createPlan (log , depl , nil , spec , status , nil , c )
234
238
assert .True (t , changed )
235
239
require .Len (t , newPlan , 3 )
236
240
assert .Equal (t , api .ActionTypeAddMember , newPlan [0 ].Type )
@@ -267,7 +271,7 @@ func TestCreatePlanClusterScale(t *testing.T) {
267
271
}
268
272
spec .DBServers .Count = util .NewInt (1 )
269
273
spec .Coordinators .Count = util .NewInt (1 )
270
- newPlan , changed = createPlan (log , depl , nil , spec , status , nil , getTLSKeyfile , getTLSCA , getPVC , createEvent )
274
+ newPlan , changed = createPlan (log , depl , nil , spec , status , nil , c )
271
275
assert .True (t , changed )
272
276
require .Len (t , newPlan , 5 ) // Note: Downscaling is done 1 at a time
273
277
assert .Equal (t , api .ActionTypeCleanOutMember , newPlan [0 ].Type )
0 commit comments