@@ -29,9 +29,10 @@ import (
29
29
"github.com/minio/mcs/cluster"
30
30
"github.com/minio/mcs/models"
31
31
"github.com/minio/mcs/restapi/operations/admin_api"
32
+ operator "github.com/minio/minio-operator/pkg/apis/operator.min.io/v1"
32
33
v1 "github.com/minio/minio-operator/pkg/apis/operator.min.io/v1"
33
- "github.com/minio/minio/pkg/madmin"
34
34
corev1 "k8s.io/api/core/v1"
35
+ "k8s.io/apimachinery/pkg/api/resource"
35
36
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
36
37
types "k8s.io/apimachinery/pkg/types"
37
38
)
@@ -77,7 +78,7 @@ func (c k8sClientMock) getService(ctx context.Context, namespace, serviceName st
77
78
return k8sclientGetServiceMock (ctx , namespace , serviceName , opts )
78
79
}
79
80
80
- func Test_TenantInfo (t * testing.T ) {
81
+ func Test_TenantInfoTenantAdminClient (t * testing.T ) {
81
82
ctx := context .Background ()
82
83
kClient := k8sClientMock {}
83
84
type args struct {
@@ -92,7 +93,6 @@ func Test_TenantInfo(t *testing.T) {
92
93
name string
93
94
args args
94
95
wantErr bool
95
- want madmin.AdminClient
96
96
mockGetSecret func (ctx context.Context , namespace , secretName string , opts metav1.GetOptions ) (* corev1.Secret , error )
97
97
mockGetService func (ctx context.Context , namespace , serviceName string , opts metav1.GetOptions ) (* corev1.Service , error )
98
98
}{
@@ -240,11 +240,91 @@ func Test_TenantInfo(t *testing.T) {
240
240
}
241
241
t .Errorf ("getTenantAdminClient() error = %v, wantErr %v" , err , tt .wantErr )
242
242
}
243
- if reflect . DeepEqual ( got , tt . want ) {
244
- t .Errorf ("got %v want %v" , got , tt . want )
243
+ if got == nil {
244
+ t .Errorf ("getTenantAdminClient() expected type: *madmin.AdminClient , got: nil" )
245
245
}
246
246
})
247
+ }
248
+ }
247
249
250
+ func Test_TenantInfo (t * testing.T ) {
251
+ testTimeStamp := metav1 .Now ()
252
+ type args struct {
253
+ minioInstance * operator.MinIOInstance
254
+ tenantInfo * usageInfo
255
+ }
256
+ tests := []struct {
257
+ name string
258
+ args args
259
+ want * models.Tenant
260
+ }{
261
+ {
262
+ name : "Get tenant Info" ,
263
+ args : args {
264
+ minioInstance : & operator.MinIOInstance {
265
+ ObjectMeta : metav1.ObjectMeta {
266
+ CreationTimestamp : testTimeStamp ,
267
+ Name : "tenant1" ,
268
+ Namespace : "minio-ns" ,
269
+ },
270
+ Spec : operator.MinIOInstanceSpec {
271
+ Zones : []operator.Zone {
272
+ {
273
+ Name : "zone1" ,
274
+ Servers : int32 (2 ),
275
+ },
276
+ },
277
+ VolumesPerServer : 4 ,
278
+ VolumeClaimTemplate : & corev1.PersistentVolumeClaim {
279
+ Spec : corev1.PersistentVolumeClaimSpec {
280
+ Resources : corev1.ResourceRequirements {
281
+ Requests : map [corev1.ResourceName ]resource.Quantity {
282
+ corev1 .ResourceStorage : resource .MustParse ("1Mi" ),
283
+ },
284
+ },
285
+ StorageClassName : swag .String ("standard" ),
286
+ },
287
+ },
288
+ Image : "minio/minio:RELEASE.2020-06-14T18-32-17Z" ,
289
+ },
290
+ Status : operator.MinIOInstanceStatus {
291
+ CurrentState : "ready" ,
292
+ },
293
+ },
294
+ tenantInfo : & usageInfo {
295
+ DisksUsage : 1024 ,
296
+ },
297
+ },
298
+ want : & models.Tenant {
299
+ CreationDate : testTimeStamp .String (),
300
+ InstanceCount : 2 , // number of servers
301
+ Name : "tenant1" ,
302
+ VolumesPerServer : int64 (4 ),
303
+ VolumeCount : int64 (8 ),
304
+ VolumeSize : int64 (1048576 ),
305
+ TotalSize : int64 (8388608 ),
306
+ ZoneCount : int64 (1 ),
307
+ CurrentState : "ready" ,
308
+ Zones : []* models.Zone {
309
+ {
310
+ Name : swag .String ("zone1" ),
311
+ Servers : swag .Int64 (int64 (2 )),
312
+ },
313
+ },
314
+ Namespace : "minio-ns" ,
315
+ Image : "minio/minio:RELEASE.2020-06-14T18-32-17Z" ,
316
+ UsedSize : int64 (1024 ),
317
+ StorageClass : "standard" ,
318
+ },
319
+ },
320
+ }
321
+ for _ , tt := range tests {
322
+ t .Run (tt .name , func (t * testing.T ) {
323
+ got := getTenantInfo (tt .args .minioInstance , tt .args .tenantInfo )
324
+ if ! reflect .DeepEqual (got , tt .want ) {
325
+ t .Errorf ("got %v want %v" , got , tt .want )
326
+ }
327
+ })
248
328
}
249
329
}
250
330
0 commit comments