Vacuum Swagger (#3533)
This commit is contained in:
@@ -1083,206 +1083,6 @@ func Test_shareObject(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func Test_putObjectLegalHold(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
client := minioClientMock{}
|
||||
type args struct {
|
||||
bucket string
|
||||
prefix string
|
||||
versionID string
|
||||
status models.ObjectLegalHoldStatus
|
||||
legalHoldFunc func(ctx context.Context, bucketName, objectName string, opts minio.PutObjectLegalHoldOptions) error
|
||||
}
|
||||
tests := []struct {
|
||||
test string
|
||||
args args
|
||||
wantError error
|
||||
}{
|
||||
{
|
||||
test: "Put Object Legal hold enabled status",
|
||||
args: args{
|
||||
bucket: "buck1",
|
||||
versionID: "someversion",
|
||||
prefix: "folder/file.txt",
|
||||
status: models.ObjectLegalHoldStatusEnabled,
|
||||
legalHoldFunc: func(_ context.Context, _, _ string, _ minio.PutObjectLegalHoldOptions) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
wantError: nil,
|
||||
},
|
||||
{
|
||||
test: "Put Object Legal hold disabled status",
|
||||
args: args{
|
||||
bucket: "buck1",
|
||||
versionID: "someversion",
|
||||
prefix: "folder/file.txt",
|
||||
status: models.ObjectLegalHoldStatusDisabled,
|
||||
legalHoldFunc: func(_ context.Context, _, _ string, _ minio.PutObjectLegalHoldOptions) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
wantError: nil,
|
||||
},
|
||||
{
|
||||
test: "Handle error on legalhold func",
|
||||
args: args{
|
||||
bucket: "buck1",
|
||||
versionID: "someversion",
|
||||
prefix: "folder/file.txt",
|
||||
status: models.ObjectLegalHoldStatusDisabled,
|
||||
legalHoldFunc: func(_ context.Context, _, _ string, _ minio.PutObjectLegalHoldOptions) error {
|
||||
return errors.New("new error")
|
||||
},
|
||||
},
|
||||
wantError: errors.New("new error"),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.test, func(_ *testing.T) {
|
||||
minioPutObjectLegalHoldMock = tt.args.legalHoldFunc
|
||||
err := setObjectLegalHold(ctx, client, tt.args.bucket, tt.args.prefix, tt.args.versionID, tt.args.status)
|
||||
if !reflect.DeepEqual(err, tt.wantError) {
|
||||
t.Errorf("setObjectLegalHold() error: %v, wantErr: %v", err, tt.wantError)
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_putObjectRetention(t *testing.T) {
|
||||
tAssert := assert.New(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
client := minioClientMock{}
|
||||
type args struct {
|
||||
bucket string
|
||||
prefix string
|
||||
versionID string
|
||||
opts *models.PutObjectRetentionRequest
|
||||
retentionFunc func(ctx context.Context, bucketName, objectName string, opts minio.PutObjectRetentionOptions) error
|
||||
}
|
||||
tests := []struct {
|
||||
test string
|
||||
args args
|
||||
wantError error
|
||||
}{
|
||||
{
|
||||
test: "Put Object retention governance",
|
||||
args: args{
|
||||
bucket: "buck1",
|
||||
versionID: "someversion",
|
||||
prefix: "folder/file.txt",
|
||||
opts: &models.PutObjectRetentionRequest{
|
||||
Expires: swag.String("2006-01-02T15:04:05Z"),
|
||||
GovernanceBypass: false,
|
||||
Mode: models.NewObjectRetentionMode(models.ObjectRetentionModeGovernance),
|
||||
},
|
||||
retentionFunc: func(_ context.Context, _, _ string, _ minio.PutObjectRetentionOptions) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
wantError: nil,
|
||||
},
|
||||
{
|
||||
test: "Put Object retention compliance",
|
||||
args: args{
|
||||
bucket: "buck1",
|
||||
versionID: "someversion",
|
||||
prefix: "folder/file.txt",
|
||||
opts: &models.PutObjectRetentionRequest{
|
||||
Expires: swag.String("2006-01-02T15:04:05Z"),
|
||||
GovernanceBypass: false,
|
||||
Mode: models.NewObjectRetentionMode(models.ObjectRetentionModeCompliance),
|
||||
},
|
||||
retentionFunc: func(_ context.Context, _, _ string, _ minio.PutObjectRetentionOptions) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
wantError: nil,
|
||||
},
|
||||
{
|
||||
test: "Empty opts should return error",
|
||||
args: args{
|
||||
bucket: "buck1",
|
||||
versionID: "someversion",
|
||||
prefix: "folder/file.txt",
|
||||
opts: nil,
|
||||
retentionFunc: func(_ context.Context, _, _ string, _ minio.PutObjectRetentionOptions) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
wantError: errors.New("object retention options can't be nil"),
|
||||
},
|
||||
{
|
||||
test: "Empty expire on opts should return error",
|
||||
args: args{
|
||||
bucket: "buck1",
|
||||
versionID: "someversion",
|
||||
prefix: "folder/file.txt",
|
||||
opts: &models.PutObjectRetentionRequest{
|
||||
Expires: nil,
|
||||
GovernanceBypass: false,
|
||||
Mode: models.NewObjectRetentionMode(models.ObjectRetentionModeCompliance),
|
||||
},
|
||||
retentionFunc: func(_ context.Context, _, _ string, _ minio.PutObjectRetentionOptions) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
wantError: errors.New("object retention expires can't be nil"),
|
||||
},
|
||||
{
|
||||
test: "Handle invalid expire time",
|
||||
args: args{
|
||||
bucket: "buck1",
|
||||
versionID: "someversion",
|
||||
prefix: "folder/file.txt",
|
||||
opts: &models.PutObjectRetentionRequest{
|
||||
Expires: swag.String("invalidtime"),
|
||||
GovernanceBypass: false,
|
||||
Mode: models.NewObjectRetentionMode(models.ObjectRetentionModeCompliance),
|
||||
},
|
||||
retentionFunc: func(_ context.Context, _, _ string, _ minio.PutObjectRetentionOptions) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
wantError: errors.New("parsing time \"invalidtime\" as \"2006-01-02T15:04:05Z07:00\": cannot parse \"invalidtime\" as \"2006\""),
|
||||
},
|
||||
{
|
||||
test: "Handle error on retention func",
|
||||
args: args{
|
||||
bucket: "buck1",
|
||||
versionID: "someversion",
|
||||
prefix: "folder/file.txt",
|
||||
opts: &models.PutObjectRetentionRequest{
|
||||
Expires: swag.String("2006-01-02T15:04:05Z"),
|
||||
GovernanceBypass: false,
|
||||
Mode: models.NewObjectRetentionMode(models.ObjectRetentionModeCompliance),
|
||||
},
|
||||
retentionFunc: func(_ context.Context, _, _ string, _ minio.PutObjectRetentionOptions) error {
|
||||
return errors.New("new Error")
|
||||
},
|
||||
},
|
||||
wantError: errors.New("new Error"),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.test, func(_ *testing.T) {
|
||||
minioPutObjectRetentionMock = tt.args.retentionFunc
|
||||
err := setObjectRetention(ctx, client, tt.args.bucket, tt.args.prefix, tt.args.versionID, tt.args.opts)
|
||||
if tt.wantError != nil {
|
||||
fmt.Println(t.Name())
|
||||
tAssert.Equal(tt.wantError.Error(), err.Error(), fmt.Sprintf("setObjectRetention() error: `%s`, wantErr: `%s`", err, tt.wantError))
|
||||
} else {
|
||||
tAssert.Nil(err, fmt.Sprintf("setObjectRetention() error: %v, wantErr: %v", err, tt.wantError))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_deleteObjectRetention(t *testing.T) {
|
||||
tAssert := assert.New(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
Reference in New Issue
Block a user