@@ -37,18 +37,40 @@ import (
3737 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
3838)
3939
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+
4071// TestCreatePlanSingleScale creates a `single` deployment to test the creating of scaling plan.
4172func 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 {}
5274 log := zerolog .Nop ()
5375 spec := api.DeploymentSpec {
5476 Mode : api .NewMode (api .DeploymentModeSingle ),
@@ -64,7 +86,7 @@ func TestCreatePlanSingleScale(t *testing.T) {
6486
6587 // Test with empty status
6688 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 )
6890 assert .True (t , changed )
6991 assert .Len (t , newPlan , 0 ) // Single mode does not scale
7092
@@ -75,7 +97,7 @@ func TestCreatePlanSingleScale(t *testing.T) {
7597 PodName : "something" ,
7698 },
7799 }
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 )
79101 assert .True (t , changed )
80102 assert .Len (t , newPlan , 0 ) // Single mode does not scale
81103
@@ -90,23 +112,14 @@ func TestCreatePlanSingleScale(t *testing.T) {
90112 PodName : "something1" ,
91113 },
92114 }
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 )
94116 assert .True (t , changed )
95117 assert .Len (t , newPlan , 0 ) // Single mode does not scale
96118}
97119
98120// TestCreatePlanActiveFailoverScale creates a `ActiveFailover` deployment to test the creating of scaling plan.
99121func 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 {}
110123 log := zerolog .Nop ()
111124 spec := api.DeploymentSpec {
112125 Mode : api .NewMode (api .DeploymentModeActiveFailover ),
@@ -123,7 +136,7 @@ func TestCreatePlanActiveFailoverScale(t *testing.T) {
123136
124137 // Test with empty status
125138 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 )
127140 assert .True (t , changed )
128141 require .Len (t , newPlan , 2 )
129142 assert .Equal (t , api .ActionTypeAddMember , newPlan [0 ].Type )
@@ -136,7 +149,7 @@ func TestCreatePlanActiveFailoverScale(t *testing.T) {
136149 PodName : "something" ,
137150 },
138151 }
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 )
140153 assert .True (t , changed )
141154 require .Len (t , newPlan , 1 )
142155 assert .Equal (t , api .ActionTypeAddMember , newPlan [0 ].Type )
@@ -161,7 +174,7 @@ func TestCreatePlanActiveFailoverScale(t *testing.T) {
161174 PodName : "something4" ,
162175 },
163176 }
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 )
165178 assert .True (t , changed )
166179 require .Len (t , newPlan , 2 ) // Note: Downscaling is only down 1 at a time
167180 assert .Equal (t , api .ActionTypeShutdownMember , newPlan [0 ].Type )
@@ -172,16 +185,7 @@ func TestCreatePlanActiveFailoverScale(t *testing.T) {
172185
173186// TestCreatePlanClusterScale creates a `cluster` deployment to test the creating of scaling plan.
174187func 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 {}
185189 log := zerolog .Nop ()
186190 spec := api.DeploymentSpec {
187191 Mode : api .NewMode (api .DeploymentModeCluster ),
@@ -197,7 +201,7 @@ func TestCreatePlanClusterScale(t *testing.T) {
197201
198202 // Test with empty status
199203 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 )
201205 assert .True (t , changed )
202206 require .Len (t , newPlan , 6 ) // Adding 3 dbservers & 3 coordinators (note: agents do not scale now)
203207 assert .Equal (t , api .ActionTypeAddMember , newPlan [0 ].Type )
@@ -230,7 +234,7 @@ func TestCreatePlanClusterScale(t *testing.T) {
230234 PodName : "coordinator1" ,
231235 },
232236 }
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 )
234238 assert .True (t , changed )
235239 require .Len (t , newPlan , 3 )
236240 assert .Equal (t , api .ActionTypeAddMember , newPlan [0 ].Type )
@@ -267,7 +271,7 @@ func TestCreatePlanClusterScale(t *testing.T) {
267271 }
268272 spec .DBServers .Count = util .NewInt (1 )
269273 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 )
271275 assert .True (t , changed )
272276 require .Len (t , newPlan , 5 ) // Note: Downscaling is done 1 at a time
273277 assert .Equal (t , api .ActionTypeCleanOutMember , newPlan [0 ].Type )
0 commit comments