Skip to content

Commit a26e183

Browse files
committed
Add missing validations on tenant info test
1 parent 812fd5f commit a26e183

File tree

1 file changed

+142
-5
lines changed

1 file changed

+142
-5
lines changed

restapi/admin_tenants_test.go

Lines changed: 142 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ func Test_TenantInfo(t *testing.T) {
257257
testTimeStamp := metav1.Now()
258258
type args struct {
259259
minioTenant *operator.Tenant
260-
tenantInfo *usageInfo
261260
}
262261
tests := []struct {
263262
name string
@@ -298,12 +297,76 @@ func Test_TenantInfo(t *testing.T) {
298297
CurrentState: "ready",
299298
},
300299
},
301-
tenantInfo: &usageInfo{
302-
DisksUsage: 1024,
300+
},
301+
want: &models.Tenant{
302+
CreationDate: testTimeStamp.String(),
303+
Name: "tenant1",
304+
TotalSize: int64(8388608),
305+
CurrentState: "ready",
306+
Zones: []*models.Zone{
307+
{
308+
Name: "zone1",
309+
Servers: swag.Int64(int64(2)),
310+
VolumesPerServer: swag.Int32(4),
311+
VolumeConfiguration: &models.ZoneVolumeConfiguration{
312+
StorageClassName: "standard",
313+
Size: swag.Int64(1024 * 1024),
314+
},
315+
},
316+
},
317+
Namespace: "minio-ns",
318+
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
319+
EnablePrometheus: false,
320+
},
321+
},
322+
{
323+
// Description if DeletionTimeStamp is present, value should be returned as string
324+
// If Prometheus annotations are present, EnablePrometheus should be returned as true
325+
// All three annotations should be defined to consider Prometheus enabled
326+
name: "Get tenant Info w DeletionTimeStamp and Prometheus",
327+
args: args{
328+
minioTenant: &operator.Tenant{
329+
ObjectMeta: metav1.ObjectMeta{
330+
CreationTimestamp: testTimeStamp,
331+
Name: "tenant1",
332+
Namespace: "minio-ns",
333+
DeletionTimestamp: &testTimeStamp,
334+
},
335+
Spec: operator.TenantSpec{
336+
Zones: []operator.Zone{
337+
{
338+
Name: "zone1",
339+
Servers: int32(2),
340+
VolumesPerServer: 4,
341+
VolumeClaimTemplate: &corev1.PersistentVolumeClaim{
342+
Spec: corev1.PersistentVolumeClaimSpec{
343+
Resources: corev1.ResourceRequirements{
344+
Requests: map[corev1.ResourceName]resource.Quantity{
345+
corev1.ResourceStorage: resource.MustParse("1Mi"),
346+
},
347+
},
348+
StorageClassName: swag.String("standard"),
349+
},
350+
},
351+
},
352+
},
353+
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
354+
Metadata: &metav1.ObjectMeta{
355+
Annotations: map[string]string{
356+
prometheusPath: "some/path",
357+
prometheusPort: "other/path",
358+
prometheusScrape: "other/path",
359+
},
360+
},
361+
},
362+
Status: operator.TenantStatus{
363+
CurrentState: "ready",
364+
},
303365
},
304366
},
305367
want: &models.Tenant{
306368
CreationDate: testTimeStamp.String(),
369+
DeletionDate: testTimeStamp.String(),
307370
Name: "tenant1",
308371
TotalSize: int64(8388608),
309372
CurrentState: "ready",
@@ -318,8 +381,82 @@ func Test_TenantInfo(t *testing.T) {
318381
},
319382
},
320383
},
321-
Namespace: "minio-ns",
322-
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
384+
Namespace: "minio-ns",
385+
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
386+
EnablePrometheus: true,
387+
},
388+
},
389+
{
390+
// If Prometheus annotations are present, EnablePrometheus should be returned as true
391+
// All three annotations should be defined to consider Prometheus enabled
392+
name: "Get tenant Info, not all Prometheus annotations",
393+
args: args{
394+
minioTenant: &operator.Tenant{
395+
ObjectMeta: metav1.ObjectMeta{
396+
CreationTimestamp: testTimeStamp,
397+
Name: "tenant1",
398+
Namespace: "minio-ns",
399+
},
400+
Spec: operator.TenantSpec{
401+
Zones: []operator.Zone{},
402+
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
403+
Metadata: &metav1.ObjectMeta{
404+
Annotations: map[string]string{
405+
prometheusPath: "some/path",
406+
prometheusScrape: "other/path",
407+
},
408+
},
409+
},
410+
Status: operator.TenantStatus{
411+
CurrentState: "ready",
412+
},
413+
},
414+
},
415+
want: &models.Tenant{
416+
CreationDate: testTimeStamp.String(),
417+
Name: "tenant1",
418+
CurrentState: "ready",
419+
Namespace: "minio-ns",
420+
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
421+
EnablePrometheus: false,
422+
},
423+
},
424+
{
425+
// If console image is set, it should be returned on tenant info
426+
name: "Get tenant Info, Console image set",
427+
args: args{
428+
minioTenant: &operator.Tenant{
429+
ObjectMeta: metav1.ObjectMeta{
430+
CreationTimestamp: testTimeStamp,
431+
Name: "tenant1",
432+
Namespace: "minio-ns",
433+
},
434+
Spec: operator.TenantSpec{
435+
Zones: []operator.Zone{},
436+
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
437+
Metadata: &metav1.ObjectMeta{
438+
Annotations: map[string]string{
439+
prometheusPath: "some/path",
440+
prometheusScrape: "other/path",
441+
},
442+
},
443+
Console: &operator.ConsoleConfiguration{
444+
Image: "minio/console:master",
445+
},
446+
},
447+
Status: operator.TenantStatus{
448+
CurrentState: "ready",
449+
},
450+
},
451+
},
452+
want: &models.Tenant{
453+
CreationDate: testTimeStamp.String(),
454+
Name: "tenant1",
455+
CurrentState: "ready",
456+
Namespace: "minio-ns",
457+
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
458+
EnablePrometheus: false,
459+
ConsoleImage: "minio/console:master",
323460
},
324461
},
325462
}

0 commit comments

Comments
 (0)