mirror of
https://github.com/minio/minio.git
synced 2025-02-03 09:55:59 -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")
|
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")
|
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")
|
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 (
|
const (
|
||||||
@ -256,7 +257,7 @@ func (lc Lifecycle) Validate(lr lock.Retention) error {
|
|||||||
!r.DelMarkerExpiration.Empty() || // DelMarkerDeleteAllVersionsAction
|
!r.DelMarkerExpiration.Empty() || // DelMarkerDeleteAllVersionsAction
|
||||||
!r.NoncurrentVersionExpiration.IsDaysNull() || // DeleteVersionAction
|
!r.NoncurrentVersionExpiration.IsDaysNull() || // DeleteVersionAction
|
||||||
!r.Expiration.IsDaysNull()) && lr.LockEnabled {
|
!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
|
// Make sure Rule ID is unique
|
||||||
|
@ -39,6 +39,7 @@ func TestParseAndValidateLifecycleConfig(t *testing.T) {
|
|||||||
inputConfig string
|
inputConfig string
|
||||||
expectedParsingErr error
|
expectedParsingErr error
|
||||||
expectedValidationErr error
|
expectedValidationErr error
|
||||||
|
lr lock.Retention
|
||||||
}{
|
}{
|
||||||
{ // Valid lifecycle config
|
{ // Valid lifecycle config
|
||||||
inputConfig: `<LifecycleConfiguration>
|
inputConfig: `<LifecycleConfiguration>
|
||||||
@ -62,6 +63,37 @@ func TestParseAndValidateLifecycleConfig(t *testing.T) {
|
|||||||
expectedParsingErr: nil,
|
expectedParsingErr: nil,
|
||||||
expectedValidationErr: 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
|
{ // Valid lifecycle config
|
||||||
inputConfig: `<LifecycleConfiguration>
|
inputConfig: `<LifecycleConfiguration>
|
||||||
<Rule>
|
<Rule>
|
||||||
@ -145,7 +177,7 @@ func TestParseAndValidateLifecycleConfig(t *testing.T) {
|
|||||||
// no need to continue this test.
|
// no need to continue this test.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = lc.Validate(lock.Retention{})
|
err = lc.Validate(tc.lr)
|
||||||
if err != tc.expectedValidationErr {
|
if err != tc.expectedValidationErr {
|
||||||
t.Fatalf("%d: Expected %v during validation but got %v", i+1, tc.expectedValidationErr, err)
|
t.Fatalf("%d: Expected %v during validation but got %v", i+1, tc.expectedValidationErr, err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user