mirror of
https://github.com/minio/minio.git
synced 2025-01-24 13:13:16 -05:00
test: add reject ilm rule test case (#19788)
This commit is contained in:
parent
ae14681c3e
commit
391baa1c9a
@ -36,6 +36,7 @@ var (
|
||||
errLifecycleNoRule = Errorf("Lifecycle configuration should have at least one rule")
|
||||
errLifecycleDuplicateID = Errorf("Rule ID must be unique. Found same ID for more than one rule")
|
||||
errXMLNotWellFormed = Errorf("The XML you provided was not well-formed or did not validate against our published schema")
|
||||
errLifecycleBucketLocked = Errorf("--expire-day, --expire-delete-marker, --expire-all-object-versions and --noncurrent-expire-days can't be used for locked bucket")
|
||||
)
|
||||
|
||||
const (
|
||||
@ -256,7 +257,7 @@ func (lc Lifecycle) Validate(lr lock.Retention) error {
|
||||
!r.DelMarkerExpiration.Empty() || // DelMarkerDeleteAllVersionsAction
|
||||
!r.NoncurrentVersionExpiration.IsDaysNull() || // DeleteVersionAction
|
||||
!r.Expiration.IsDaysNull()) && lr.LockEnabled {
|
||||
return fmt.Errorf("DeleteAllVersions and DeleteMarkerDeleteAllVersions cannot be set when bucket lock is enabled")
|
||||
return errLifecycleBucketLocked
|
||||
}
|
||||
}
|
||||
// Make sure Rule ID is unique
|
||||
|
@ -39,6 +39,7 @@ func TestParseAndValidateLifecycleConfig(t *testing.T) {
|
||||
inputConfig string
|
||||
expectedParsingErr error
|
||||
expectedValidationErr error
|
||||
lr lock.Retention
|
||||
}{
|
||||
{ // Valid lifecycle config
|
||||
inputConfig: `<LifecycleConfiguration>
|
||||
@ -62,6 +63,37 @@ func TestParseAndValidateLifecycleConfig(t *testing.T) {
|
||||
expectedParsingErr: nil,
|
||||
expectedValidationErr: nil,
|
||||
},
|
||||
{ // invalid lifecycle config
|
||||
inputConfig: `<LifecycleConfiguration>
|
||||
<Rule>
|
||||
<ID>testRule1</ID>
|
||||
<Filter>
|
||||
<Prefix>prefix</Prefix>
|
||||
</Filter>
|
||||
<Status>Enabled</Status>
|
||||
<Expiration><Days>3</Days></Expiration>
|
||||
</Rule>
|
||||
<Rule>
|
||||
<ID>testRule2</ID>
|
||||
<Filter>
|
||||
<Prefix>another-prefix</Prefix>
|
||||
</Filter>
|
||||
<Status>Enabled</Status>
|
||||
<Expiration><Days>3</Days></Expiration>
|
||||
</Rule>
|
||||
</LifecycleConfiguration>`,
|
||||
expectedParsingErr: nil,
|
||||
expectedValidationErr: errLifecycleBucketLocked,
|
||||
lr: lock.Retention{
|
||||
LockEnabled: true,
|
||||
},
|
||||
},
|
||||
{ // lifecycle config with no rules
|
||||
inputConfig: `<LifecycleConfiguration>
|
||||
</LifecycleConfiguration>`,
|
||||
expectedParsingErr: nil,
|
||||
expectedValidationErr: errLifecycleNoRule,
|
||||
},
|
||||
{ // Valid lifecycle config
|
||||
inputConfig: `<LifecycleConfiguration>
|
||||
<Rule>
|
||||
@ -145,7 +177,7 @@ func TestParseAndValidateLifecycleConfig(t *testing.T) {
|
||||
// no need to continue this test.
|
||||
return
|
||||
}
|
||||
err = lc.Validate(lock.Retention{})
|
||||
err = lc.Validate(tc.lr)
|
||||
if err != tc.expectedValidationErr {
|
||||
t.Fatalf("%d: Expected %v during validation but got %v", i+1, tc.expectedValidationErr, err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user