@@ -362,56 +362,6 @@ func TestSetBucketAccess(t *testing.T) {
362362 }
363363}
364364
365- func Test_enableBucketEncryption (t * testing.T ) {
366- ctx := context .Background ()
367- type args struct {
368- ctx context.Context
369- bucketName string
370- encryptionType models.BucketEncryptionType
371- kmsKeyID string
372- mockEnableBucketEncryptionFunc func (ctx context.Context , bucketName string , config * sse.Configuration ) error
373- }
374- tests := []struct {
375- name string
376- args args
377- wantErr bool
378- }{
379- {
380- name : "Bucket encryption enabled correctly" ,
381- args : args {
382- ctx : ctx ,
383- bucketName : "test" ,
384- encryptionType : "sse-s3" ,
385- mockEnableBucketEncryptionFunc : func (_ context.Context , _ string , _ * sse.Configuration ) error {
386- return nil
387- },
388- },
389- wantErr : false ,
390- },
391- {
392- name : "Error when enabling bucket encryption" ,
393- args : args {
394- ctx : ctx ,
395- bucketName : "test" ,
396- encryptionType : "sse-s3" ,
397- mockEnableBucketEncryptionFunc : func (_ context.Context , _ string , _ * sse.Configuration ) error {
398- return ErrInvalidSession
399- },
400- },
401- wantErr : true ,
402- },
403- }
404- for _ , tt := range tests {
405- t .Run (tt .name , func (_ * testing.T ) {
406- minClient := minioClientMock {}
407- minClient .setBucketEncryptionMock = tt .args .mockEnableBucketEncryptionFunc
408- if err := enableBucketEncryption (tt .args .ctx , minClient , tt .args .bucketName , tt .args .encryptionType , tt .args .kmsKeyID ); (err != nil ) != tt .wantErr {
409- t .Errorf ("enableBucketEncryption() errors = %v, wantErr %v" , err , tt .wantErr )
410- }
411- })
412- }
413- }
414-
415365func Test_disableBucketEncryption (t * testing.T ) {
416366 ctx := context .Background ()
417367 type args struct {
@@ -458,197 +408,6 @@ func Test_disableBucketEncryption(t *testing.T) {
458408 }
459409}
460410
461- func Test_getBucketEncryptionInfo (t * testing.T ) {
462- ctx := context .Background ()
463- type args struct {
464- ctx context.Context
465- bucketName string
466- mockBucketEncryptionGet func (ctx context.Context , bucketName string ) (* sse.Configuration , error )
467- }
468- tests := []struct {
469- name string
470- args args
471- want * models.BucketEncryptionInfo
472- wantErr bool
473- }{
474- {
475- name : "Bucket encryption info returned correctly" ,
476- args : args {
477- ctx : ctx ,
478- bucketName : "test" ,
479- mockBucketEncryptionGet : func (_ context.Context , _ string ) (* sse.Configuration , error ) {
480- return & sse.Configuration {
481- Rules : []sse.Rule {
482- {
483- Apply : sse.ApplySSEByDefault {SSEAlgorithm : "AES256" , KmsMasterKeyID : "" },
484- },
485- },
486- }, nil
487- },
488- },
489- wantErr : false ,
490- want : & models.BucketEncryptionInfo {
491- Algorithm : "AES256" ,
492- KmsMasterKeyID : "" ,
493- },
494- },
495- {
496- name : "Bucket encryption info with no rules" ,
497- args : args {
498- ctx : ctx ,
499- bucketName : "test" ,
500- mockBucketEncryptionGet : func (_ context.Context , _ string ) (* sse.Configuration , error ) {
501- return & sse.Configuration {
502- Rules : []sse.Rule {},
503- }, nil
504- },
505- },
506- wantErr : true ,
507- },
508- {
509- name : "Error when obtaining bucket encryption info" ,
510- args : args {
511- ctx : ctx ,
512- bucketName : "test" ,
513- mockBucketEncryptionGet : func (_ context.Context , _ string ) (* sse.Configuration , error ) {
514- return nil , ErrSSENotConfigured
515- },
516- },
517- wantErr : true ,
518- },
519- }
520- for _ , tt := range tests {
521- t .Run (tt .name , func (_ * testing.T ) {
522- minClient := minioClientMock {}
523- minClient .getBucketEncryptionMock = tt .args .mockBucketEncryptionGet
524- got , err := getBucketEncryptionInfo (tt .args .ctx , minClient , tt .args .bucketName )
525- if (err != nil ) != tt .wantErr {
526- t .Errorf ("getBucketEncryptionInfo() errors = %v, wantErr %v" , err , tt .wantErr )
527- return
528- }
529- if ! reflect .DeepEqual (got , tt .want ) {
530- t .Errorf ("getBucketEncryptionInfo() got = %v, want %v" , got , tt .want )
531- }
532- })
533- }
534- }
535-
536- func Test_SetBucketRetentionConfig (t * testing.T ) {
537- assert := assert .New (t )
538- ctx := context .Background ()
539- type args struct {
540- ctx context.Context
541- bucketName string
542- mode models.ObjectRetentionMode
543- unit models.ObjectRetentionUnit
544- validity * int32
545- mockBucketRetentionFunc func (ctx context.Context , bucketName string , mode * minio.RetentionMode , validity * uint , unit * minio.ValidityUnit ) error
546- }
547- tests := []struct {
548- name string
549- args args
550- expectedError error
551- }{
552- {
553- name : "Set Bucket Retention Config" ,
554- args : args {
555- ctx : ctx ,
556- bucketName : "test" ,
557- mode : models .ObjectRetentionModeCompliance ,
558- unit : models .ObjectRetentionUnitDays ,
559- validity : swag .Int32 (2 ),
560- mockBucketRetentionFunc : func (_ context.Context , _ string , _ * minio.RetentionMode , _ * uint , _ * minio.ValidityUnit ) error {
561- return nil
562- },
563- },
564- expectedError : nil ,
565- },
566- {
567- name : "Set Bucket Retention Config 2" ,
568- args : args {
569- ctx : ctx ,
570- bucketName : "test" ,
571- mode : models .ObjectRetentionModeGovernance ,
572- unit : models .ObjectRetentionUnitYears ,
573- validity : swag .Int32 (2 ),
574- mockBucketRetentionFunc : func (_ context.Context , _ string , _ * minio.RetentionMode , _ * uint , _ * minio.ValidityUnit ) error {
575- return nil
576- },
577- },
578- expectedError : nil ,
579- },
580- {
581- name : "Invalid validity" ,
582- args : args {
583- ctx : ctx ,
584- bucketName : "test" ,
585- mode : models .ObjectRetentionModeCompliance ,
586- unit : models .ObjectRetentionUnitDays ,
587- validity : nil ,
588- mockBucketRetentionFunc : func (_ context.Context , _ string , _ * minio.RetentionMode , _ * uint , _ * minio.ValidityUnit ) error {
589- return nil
590- },
591- },
592- expectedError : errors .New ("retention validity can't be nil" ),
593- },
594- {
595- name : "Invalid retention mode" ,
596- args : args {
597- ctx : ctx ,
598- bucketName : "test" ,
599- mode : models .ObjectRetentionMode ("othermode" ),
600- unit : models .ObjectRetentionUnitDays ,
601- validity : swag .Int32 (2 ),
602- mockBucketRetentionFunc : func (_ context.Context , _ string , _ * minio.RetentionMode , _ * uint , _ * minio.ValidityUnit ) error {
603- return nil
604- },
605- },
606- expectedError : errors .New ("invalid retention mode" ),
607- },
608- {
609- name : "Invalid retention unit" ,
610- args : args {
611- ctx : ctx ,
612- bucketName : "test" ,
613- mode : models .ObjectRetentionModeCompliance ,
614- unit : models .ObjectRetentionUnit ("otherunit" ),
615- validity : swag .Int32 (2 ),
616- mockBucketRetentionFunc : func (_ context.Context , _ string , _ * minio.RetentionMode , _ * uint , _ * minio.ValidityUnit ) error {
617- return nil
618- },
619- },
620- expectedError : errors .New ("invalid retention unit" ),
621- },
622- {
623- name : "Handle errors on objec lock function" ,
624- args : args {
625- ctx : ctx ,
626- bucketName : "test" ,
627- mode : models .ObjectRetentionModeCompliance ,
628- unit : models .ObjectRetentionUnitDays ,
629- validity : swag .Int32 (2 ),
630- mockBucketRetentionFunc : func (_ context.Context , _ string , _ * minio.RetentionMode , _ * uint , _ * minio.ValidityUnit ) error {
631- return errors .New ("error func" )
632- },
633- },
634- expectedError : errors .New ("error func" ),
635- },
636- }
637- for _ , tt := range tests {
638- t .Run (tt .name , func (_ * testing.T ) {
639- minClient := minioClientMock {}
640- minClient .setObjectLockConfigMock = tt .args .mockBucketRetentionFunc
641- err := setBucketRetentionConfig (tt .args .ctx , minClient , tt .args .bucketName , tt .args .mode , tt .args .unit , tt .args .validity )
642- if tt .expectedError != nil {
643- fmt .Println (t .Name ())
644- assert .Equal (tt .expectedError .Error (), err .Error (), fmt .Sprintf ("setObjectRetention() errors: `%s`, wantErr: `%s`" , err , tt .expectedError ))
645- } else {
646- assert .Nil (err , fmt .Sprintf ("setBucketRetentionConfig() errors: %v, wantErr: %v" , err , tt .expectedError ))
647- }
648- })
649- }
650- }
651-
652411func Test_GetBucketRetentionConfig (t * testing.T ) {
653412 assert := assert .New (t )
654413 ctx := context .Background ()
0 commit comments