@@ -29,9 +29,10 @@ import (
2929 "github.com/minio/mcs/cluster"
3030 "github.com/minio/mcs/models"
3131 "github.com/minio/mcs/restapi/operations/admin_api"
32+ operator "github.com/minio/minio-operator/pkg/apis/operator.min.io/v1"
3233 v1 "github.com/minio/minio-operator/pkg/apis/operator.min.io/v1"
33- "github.com/minio/minio/pkg/madmin"
3434 corev1 "k8s.io/api/core/v1"
35+ "k8s.io/apimachinery/pkg/api/resource"
3536 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3637 types "k8s.io/apimachinery/pkg/types"
3738)
@@ -77,7 +78,7 @@ func (c k8sClientMock) getService(ctx context.Context, namespace, serviceName st
7778 return k8sclientGetServiceMock (ctx , namespace , serviceName , opts )
7879}
7980
80- func Test_TenantInfo (t * testing.T ) {
81+ func Test_TenantInfoTenantAdminClient (t * testing.T ) {
8182 ctx := context .Background ()
8283 kClient := k8sClientMock {}
8384 type args struct {
@@ -92,7 +93,6 @@ func Test_TenantInfo(t *testing.T) {
9293 name string
9394 args args
9495 wantErr bool
95- want madmin.AdminClient
9696 mockGetSecret func (ctx context.Context , namespace , secretName string , opts metav1.GetOptions ) (* corev1.Secret , error )
9797 mockGetService func (ctx context.Context , namespace , serviceName string , opts metav1.GetOptions ) (* corev1.Service , error )
9898 }{
@@ -240,11 +240,91 @@ func Test_TenantInfo(t *testing.T) {
240240 }
241241 t .Errorf ("getTenantAdminClient() error = %v, wantErr %v" , err , tt .wantErr )
242242 }
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" )
245245 }
246246 })
247+ }
248+ }
247249
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+ })
248328 }
249329}
250330
0 commit comments