|
|
@ -24,7 +24,7 @@ import ( |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func TestParseLifecycleConfig(t *testing.T) { |
|
|
|
func TestParseAndValidateLifecycleConfig(t *testing.T) { |
|
|
|
// Test for lifecycle config with more than 1000 rules
|
|
|
|
// Test for lifecycle config with more than 1000 rules
|
|
|
|
var manyRules []Rule |
|
|
|
var manyRules []Rule |
|
|
|
rule := Rule{ |
|
|
|
rule := Rule{ |
|
|
@ -65,7 +65,8 @@ func TestParseLifecycleConfig(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
testCases := []struct { |
|
|
|
testCases := []struct { |
|
|
|
inputConfig string |
|
|
|
inputConfig string |
|
|
|
expectedErr error |
|
|
|
expectedParsingErr error |
|
|
|
|
|
|
|
expectedValidationErr error |
|
|
|
}{ |
|
|
|
}{ |
|
|
|
{ // Valid lifecycle config
|
|
|
|
{ // Valid lifecycle config
|
|
|
|
inputConfig: `<LifecycleConfiguration> |
|
|
|
inputConfig: `<LifecycleConfiguration> |
|
|
@ -84,28 +85,36 @@ func TestParseLifecycleConfig(t *testing.T) { |
|
|
|
<Expiration><Days>3</Days></Expiration> |
|
|
|
<Expiration><Days>3</Days></Expiration> |
|
|
|
</Rule> |
|
|
|
</Rule> |
|
|
|
</LifecycleConfiguration>`, |
|
|
|
</LifecycleConfiguration>`, |
|
|
|
expectedErr: nil, |
|
|
|
expectedParsingErr: nil, |
|
|
|
|
|
|
|
expectedValidationErr: nil, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ // lifecycle config with no rules
|
|
|
|
{ // lifecycle config with no rules
|
|
|
|
inputConfig: `<LifecycleConfiguration> |
|
|
|
inputConfig: `<LifecycleConfiguration> |
|
|
|
</LifecycleConfiguration>`, |
|
|
|
</LifecycleConfiguration>`, |
|
|
|
expectedErr: errLifecycleNoRule, |
|
|
|
expectedParsingErr: nil, |
|
|
|
|
|
|
|
expectedValidationErr: errLifecycleNoRule, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ // lifecycle config with more than 1000 rules
|
|
|
|
{ // lifecycle config with more than 1000 rules
|
|
|
|
inputConfig: string(manyRuleLcConfig), |
|
|
|
inputConfig: string(manyRuleLcConfig), |
|
|
|
expectedErr: errLifecycleTooManyRules, |
|
|
|
expectedParsingErr: nil, |
|
|
|
|
|
|
|
expectedValidationErr: errLifecycleTooManyRules, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ // lifecycle config with rules having overlapping prefix
|
|
|
|
{ // lifecycle config with rules having overlapping prefix
|
|
|
|
inputConfig: string(overlappingLcConfig), |
|
|
|
inputConfig: string(overlappingLcConfig), |
|
|
|
expectedErr: errLifecycleOverlappingPrefix, |
|
|
|
expectedParsingErr: nil, |
|
|
|
|
|
|
|
expectedValidationErr: errLifecycleOverlappingPrefix, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for i, tc := range testCases { |
|
|
|
for i, tc := range testCases { |
|
|
|
t.Run(fmt.Sprintf("Test %d", i+1), func(t *testing.T) { |
|
|
|
t.Run(fmt.Sprintf("Test %d", i+1), func(t *testing.T) { |
|
|
|
var err error |
|
|
|
lc, err := ParseLifecycleConfig(bytes.NewReader([]byte(tc.inputConfig))) |
|
|
|
if _, err = ParseLifecycleConfig(bytes.NewReader([]byte(tc.inputConfig))); err != tc.expectedErr { |
|
|
|
if err != tc.expectedParsingErr { |
|
|
|
t.Fatalf("%d: Expected %v but got %v", i+1, tc.expectedErr, err) |
|
|
|
t.Fatalf("%d: Expected %v during parsing but got %v", i+1, tc.expectedParsingErr, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
err = lc.Validate() |
|
|
|
|
|
|
|
if err != tc.expectedValidationErr { |
|
|
|
|
|
|
|
t.Fatalf("%d: Expected %v during parsing but got %v", i+1, tc.expectedValidationErr, err) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|