@@ -41,14 +41,25 @@ import (
41
41
42
42
var _ proto.ControllerServer = (* csi .ControllerService )(nil )
43
43
44
- type csiTestSuite struct {
44
+ type baseCSITestSuite struct {
45
45
suite.Suite
46
-
47
46
s * csi.ControllerService
48
47
}
49
48
50
- func (ts * csiTestSuite ) SetupTest () {
51
- cfg , err := proxmox .ReadCloudConfig (strings .NewReader (`
49
+ type configTestCase struct {
50
+ name string
51
+ config string
52
+ providerID string
53
+ }
54
+
55
+ func getTestConfigs () []configTestCase {
56
+ return []configTestCase {
57
+ {
58
+ name : "CapMoxProvider" ,
59
+ providerID : "proxmox://11833f4c-341f-4bd3-aad7-f7abeda472e6" ,
60
+ config : `
61
+ features:
62
+ provider: capmox
52
63
clusters:
53
64
- url: https://127.0.0.1:8006/api2/json
54
65
insecure: false
@@ -59,12 +70,36 @@ clusters:
59
70
insecure: false
60
71
token_id: "user!token-id"
61
72
token_secret: "secret"
62
- region: cluster-2
63
- ` ))
64
- if err != nil {
65
- ts .T ().Fatalf ("failed to read config: %v" , err )
73
+ region: cluster-2` ,
74
+ },
75
+ {
76
+ name : "ExplicitDefaultProvider" ,
77
+ providerID : "proxmox://cluster-1/101" ,
78
+ config : `
79
+ features:
80
+ provider: capmox
81
+ clusters:
82
+ - url: https://127.0.0.1:8006/api2/json
83
+ insecure: false
84
+ token_id: "user!token-id"
85
+ token_secret: "secret"
86
+ region: cluster-1` ,
87
+ },
88
+ {
89
+ name : "ImplicitDefaultProvider" ,
90
+ providerID : "proxmox://cluster-1/101" ,
91
+ config : `
92
+ clusters:
93
+ - url: https://127.0.0.1:8006/api2/json
94
+ insecure: false
95
+ token_id: "user!token-id"
96
+ token_secret: "secret"
97
+ region: cluster-1` ,
98
+ },
66
99
}
100
+ }
67
101
102
+ func setupMockResponders () {
68
103
httpmock .RegisterResponder ("GET" , "https://127.0.0.1:8006/api2/json/cluster/resources" ,
69
104
func (_ * http.Request ) (* http.Response , error ) {
70
105
return httpmock .NewJsonResponse (200 , map [string ]interface {}{
@@ -286,10 +321,12 @@ clusters:
286
321
})
287
322
},
288
323
)
324
+ }
289
325
290
- cluster , err := proxmox .NewCluster (& cfg , & http.Client {})
326
+ func (ts * baseCSITestSuite ) setupTestSuite (config string , providerID string ) error {
327
+ cfg , err := proxmox .ReadCloudConfig (strings .NewReader (config ))
291
328
if err != nil {
292
- ts . T (). Fatalf ( "failed to create proxmox cluster client : %v" , err )
329
+ return fmt . Errorf ( "failed to read config : %v" , err )
293
330
}
294
331
295
332
nodes := & corev1.NodeList {
@@ -303,22 +340,56 @@ clusters:
303
340
Name : "cluster-1-node-2" ,
304
341
},
305
342
Spec : corev1.NodeSpec {
306
- ProviderID : "proxmox://cluster-1/101" ,
343
+ ProviderID : providerID ,
307
344
},
308
345
},
309
346
},
310
347
}
311
348
312
349
kclient := fake .NewSimpleClientset (nodes )
313
350
351
+ cluster , err := proxmox .NewCluster (& cfg , & http.Client {})
352
+ if err != nil {
353
+ return fmt .Errorf ("failed to create proxmox cluster client: %v" , err )
354
+ }
355
+
314
356
ts .s = & csi.ControllerService {
315
- Cluster : cluster ,
316
- Kclient : kclient ,
357
+ Cluster : cluster ,
358
+ Kclient : kclient ,
359
+ Provider : cfg .Features .Provider ,
360
+ }
361
+
362
+ return nil
363
+ }
364
+
365
+ // TestSuiteCSI runs all test configurations
366
+ func TestSuiteCSI (t * testing.T ) {
367
+ configs := getTestConfigs ()
368
+ for _ , cfg := range configs {
369
+ // Create a new test suite for each configuration
370
+ ts := & baseCSITestSuite {}
371
+
372
+ // Run the suite with the current configuration
373
+ suite .Run (t , & configuredTestSuite {
374
+ baseCSITestSuite : ts ,
375
+ configCase : cfg ,
376
+ })
317
377
}
318
378
}
319
379
320
- func TestSuiteCCM (t * testing.T ) {
321
- suite .Run (t , new (csiTestSuite ))
380
+ // configuredTestSuite wraps the base suite with a specific configuration
381
+ type configuredTestSuite struct {
382
+ * baseCSITestSuite
383
+ configCase configTestCase
384
+ }
385
+
386
+ func (ts * configuredTestSuite ) SetupTest () {
387
+ setupMockResponders ()
388
+
389
+ err := ts .setupTestSuite (ts .configCase .config , ts .configCase .providerID )
390
+ if err != nil {
391
+ ts .T ().Fatalf ("Failed to setup test suite: %v" , err )
392
+ }
322
393
}
323
394
324
395
func TestNewControllerService (t * testing.T ) {
@@ -333,7 +404,7 @@ func TestNewControllerService(t *testing.T) {
333
404
}
334
405
335
406
//nolint:dupl
336
- func (ts * csiTestSuite ) TestCreateVolume () {
407
+ func (ts * configuredTestSuite ) TestCreateVolume () {
337
408
httpmock .Activate ()
338
409
defer httpmock .DeactivateAndReset ()
339
410
@@ -682,7 +753,7 @@ func (ts *csiTestSuite) TestCreateVolume() {
682
753
}
683
754
684
755
//nolint:dupl
685
- func (ts * csiTestSuite ) TestDeleteVolume () {
756
+ func (ts * configuredTestSuite ) TestDeleteVolume () {
686
757
httpmock .Activate ()
687
758
defer httpmock .DeactivateAndReset ()
688
759
@@ -758,7 +829,7 @@ func (ts *csiTestSuite) TestDeleteVolume() {
758
829
}
759
830
}
760
831
761
- func (ts * csiTestSuite ) TestControllerServiceControllerGetCapabilities () {
832
+ func (ts * configuredTestSuite ) TestControllerServiceControllerGetCapabilities () {
762
833
resp , err := ts .s .ControllerGetCapabilities (context .Background (), & proto.ControllerGetCapabilitiesRequest {})
763
834
ts .Require ().NoError (err )
764
835
ts .Require ().NotNil (resp )
@@ -769,7 +840,7 @@ func (ts *csiTestSuite) TestControllerServiceControllerGetCapabilities() {
769
840
}
770
841
771
842
//nolint:dupl
772
- func (ts * csiTestSuite ) TestControllerPublishVolumeError () {
843
+ func (ts * configuredTestSuite ) TestControllerPublishVolumeError () {
773
844
httpmock .Activate ()
774
845
defer httpmock .DeactivateAndReset ()
775
846
@@ -903,7 +974,7 @@ func (ts *csiTestSuite) TestControllerPublishVolumeError() {
903
974
}
904
975
905
976
//nolint:dupl
906
- func (ts * csiTestSuite ) TestControllerUnpublishVolumeError () {
977
+ func (ts * configuredTestSuite ) TestControllerUnpublishVolumeError () {
907
978
httpmock .Activate ()
908
979
defer httpmock .DeactivateAndReset ()
909
980
@@ -975,19 +1046,19 @@ func (ts *csiTestSuite) TestControllerUnpublishVolumeError() {
975
1046
}
976
1047
}
977
1048
978
- func (ts * csiTestSuite ) TestValidateVolumeCapabilities () {
1049
+ func (ts * configuredTestSuite ) TestValidateVolumeCapabilities () {
979
1050
_ , err := ts .s .ValidateVolumeCapabilities (context .Background (), & proto.ValidateVolumeCapabilitiesRequest {})
980
1051
ts .Require ().Error (err )
981
1052
ts .Require ().Equal (status .Error (codes .Unimplemented , "" ), err )
982
1053
}
983
1054
984
- func (ts * csiTestSuite ) TestListVolumes () {
1055
+ func (ts * configuredTestSuite ) TestListVolumes () {
985
1056
_ , err := ts .s .ListVolumes (context .Background (), & proto.ListVolumesRequest {})
986
1057
ts .Require ().Error (err )
987
1058
ts .Require ().Equal (status .Error (codes .Unimplemented , "" ), err )
988
1059
}
989
1060
990
- func (ts * csiTestSuite ) TestGetCapacity () {
1061
+ func (ts * configuredTestSuite ) TestGetCapacity () {
991
1062
httpmock .Activate ()
992
1063
defer httpmock .DeactivateAndReset ()
993
1064
@@ -1115,25 +1186,25 @@ func (ts *csiTestSuite) TestGetCapacity() {
1115
1186
}
1116
1187
}
1117
1188
1118
- func (ts * csiTestSuite ) TestCreateSnapshot () {
1189
+ func (ts * configuredTestSuite ) TestCreateSnapshot () {
1119
1190
_ , err := ts .s .CreateSnapshot (context .Background (), & proto.CreateSnapshotRequest {})
1120
1191
ts .Require ().Error (err )
1121
1192
ts .Require ().Equal (status .Error (codes .Unimplemented , "" ), err )
1122
1193
}
1123
1194
1124
- func (ts * csiTestSuite ) TestDeleteSnapshot () {
1195
+ func (ts * configuredTestSuite ) TestDeleteSnapshot () {
1125
1196
_ , err := ts .s .DeleteSnapshot (context .Background (), & proto.DeleteSnapshotRequest {})
1126
1197
ts .Require ().Error (err )
1127
1198
ts .Require ().Equal (status .Error (codes .Unimplemented , "" ), err )
1128
1199
}
1129
1200
1130
- func (ts * csiTestSuite ) TestListSnapshots () {
1201
+ func (ts * configuredTestSuite ) TestListSnapshots () {
1131
1202
_ , err := ts .s .ListSnapshots (context .Background (), & proto.ListSnapshotsRequest {})
1132
1203
ts .Require ().Error (err )
1133
1204
ts .Require ().Equal (status .Error (codes .Unimplemented , "" ), err )
1134
1205
}
1135
1206
1136
- func (ts * csiTestSuite ) TestControllerExpandVolumeError () {
1207
+ func (ts * configuredTestSuite ) TestControllerExpandVolumeError () {
1137
1208
httpmock .Activate ()
1138
1209
defer httpmock .DeactivateAndReset ()
1139
1210
@@ -1249,7 +1320,7 @@ func (ts *csiTestSuite) TestControllerExpandVolumeError() {
1249
1320
}
1250
1321
}
1251
1322
1252
- func (ts * csiTestSuite ) TestControllerGetVolume () {
1323
+ func (ts * configuredTestSuite ) TestControllerGetVolume () {
1253
1324
_ , err := ts .s .ControllerGetVolume (context .Background (), & proto.ControllerGetVolumeRequest {})
1254
1325
ts .Require ().Error (err )
1255
1326
ts .Require ().Equal (status .Error (codes .Unimplemented , "" ), err )
0 commit comments