@@ -25,6 +25,7 @@ import (
2525 "reflect"
2626 "testing"
2727
28+ "github.com/go-openapi/swag"
2829 "github.com/minio/mcs/cluster"
2930 "github.com/minio/mcs/models"
3031 "github.com/minio/mcs/restapi/operations/admin_api"
@@ -299,6 +300,97 @@ func Test_deleteTenantAction(t *testing.T) {
299300 }
300301}
301302
303+ func Test_TenantAddZone (t * testing.T ) {
304+ opClient := opClientMock {}
305+
306+ type args struct {
307+ ctx context.Context
308+ operatorClient OperatorClient
309+ nameSpace string
310+ mockMinioInstancePatch func (ctx context.Context , namespace string , instanceName string , pt types.PatchType , data []byte , options metav1.PatchOptions ) (* v1.MinIOInstance , error )
311+ mockMinioInstanceGet func (ctx context.Context , namespace string , instanceName string , options metav1.GetOptions ) (* v1.MinIOInstance , error )
312+ params admin_api.TenantAddZoneParams
313+ }
314+ tests := []struct {
315+ name string
316+ args args
317+ wantErr bool
318+ }{
319+ {
320+ name : "Add zone, no errors" ,
321+ args : args {
322+ ctx : context .Background (),
323+ operatorClient : opClient ,
324+ nameSpace : "default" ,
325+ mockMinioInstancePatch : func (ctx context.Context , namespace string , instanceName string , pt types.PatchType , data []byte , options metav1.PatchOptions ) (* v1.MinIOInstance , error ) {
326+ return & v1.MinIOInstance {}, nil
327+ },
328+ mockMinioInstanceGet : func (ctx context.Context , namespace string , instanceName string , options metav1.GetOptions ) (* v1.MinIOInstance , error ) {
329+ return & v1.MinIOInstance {}, nil
330+ },
331+ params : admin_api.TenantAddZoneParams {
332+ Body : & models.Zone {
333+ Name : swag .String ("zone-1" ),
334+ Servers : swag .Int64 (int64 (4 )),
335+ },
336+ },
337+ },
338+ wantErr : false ,
339+ },
340+ {
341+ name : "Error on patch, handle error" ,
342+ args : args {
343+ ctx : context .Background (),
344+ operatorClient : opClient ,
345+ nameSpace : "default" ,
346+ mockMinioInstancePatch : func (ctx context.Context , namespace string , instanceName string , pt types.PatchType , data []byte , options metav1.PatchOptions ) (* v1.MinIOInstance , error ) {
347+ return nil , errors .New ("errors" )
348+ },
349+ mockMinioInstanceGet : func (ctx context.Context , namespace string , instanceName string , options metav1.GetOptions ) (* v1.MinIOInstance , error ) {
350+ return & v1.MinIOInstance {}, nil
351+ },
352+ params : admin_api.TenantAddZoneParams {
353+ Body : & models.Zone {
354+ Name : swag .String ("zone-1" ),
355+ Servers : swag .Int64 (int64 (4 )),
356+ },
357+ },
358+ },
359+ wantErr : true ,
360+ },
361+ {
362+ name : "Error on get, handle error" ,
363+ args : args {
364+ ctx : context .Background (),
365+ operatorClient : opClient ,
366+ nameSpace : "default" ,
367+ mockMinioInstancePatch : func (ctx context.Context , namespace string , instanceName string , pt types.PatchType , data []byte , options metav1.PatchOptions ) (* v1.MinIOInstance , error ) {
368+ return nil , errors .New ("errors" )
369+ },
370+ mockMinioInstanceGet : func (ctx context.Context , namespace string , instanceName string , options metav1.GetOptions ) (* v1.MinIOInstance , error ) {
371+ return nil , errors .New ("errors" )
372+ },
373+ params : admin_api.TenantAddZoneParams {
374+ Body : & models.Zone {
375+ Name : swag .String ("zone-1" ),
376+ Servers : swag .Int64 (int64 (4 )),
377+ },
378+ },
379+ },
380+ wantErr : true ,
381+ },
382+ }
383+ for _ , tt := range tests {
384+ opClientMinioInstanceGetMock = tt .args .mockMinioInstanceGet
385+ opClientMinioInstancePatchMock = tt .args .mockMinioInstancePatch
386+ t .Run (tt .name , func (t * testing.T ) {
387+ if err := addTenantZone (tt .args .ctx , tt .args .operatorClient , tt .args .params ); (err != nil ) != tt .wantErr {
388+ t .Errorf ("addTenantZone() error = %v, wantErr %v" , err , tt .wantErr )
389+ }
390+ })
391+ }
392+ }
393+
302394func Test_UpdateTenantAction (t * testing.T ) {
303395 opClient := opClientMock {}
304396 httpClientM := httpClientMock {}
0 commit comments