diff --git a/pkg/lifecycle/lifecycle.go b/pkg/lifecycle/lifecycle.go index 96f1101ca..743d8eca9 100644 --- a/pkg/lifecycle/lifecycle.go +++ b/pkg/lifecycle/lifecycle.go @@ -53,12 +53,12 @@ func (n AbortIncompleteMultipartUpload) MarshalXML(e *xml.Encoder, start xml.Sta // (or suspended) to request server delete noncurrent object versions at a // specific period in the object's lifetime. type NoncurrentVersionExpiration struct { - XMLName xml.Name `xml:"NoncurrentVersionExpiration" json:"-"` - NoncurrentDays ExpirationDays `xml:"NoncurrentDays,omitempty"` - MaxNoncurrentVersions int `xml:"MaxNoncurrentVersions,omitempty"` + XMLName xml.Name `xml:"NoncurrentVersionExpiration" json:"-"` + NoncurrentDays ExpirationDays `xml:"NoncurrentDays,omitempty"` + NewerNoncurrentVersions int `xml:"NewerNoncurrentVersions,omitempty"` } -// MarshalXML if non-current days not set to non zero value +// MarshalXML if n is non-empty, i.e has a non-zero NoncurrentDays or NewerNoncurrentVersions. func (n NoncurrentVersionExpiration) MarshalXML(e *xml.Encoder, start xml.StartElement) error { if n.isNull() { return nil @@ -73,16 +73,17 @@ func (n NoncurrentVersionExpiration) IsDaysNull() bool { } func (n NoncurrentVersionExpiration) isNull() bool { - return n.IsDaysNull() && n.MaxNoncurrentVersions == 0 + return n.IsDaysNull() && n.NewerNoncurrentVersions == 0 } // NoncurrentVersionTransition structure, set this action to request server to // transition noncurrent object versions to different set storage classes // at a specific period in the object's lifetime. type NoncurrentVersionTransition struct { - XMLName xml.Name `xml:"NoncurrentVersionTransition,omitempty" json:"-"` - StorageClass string `xml:"StorageClass,omitempty" json:"StorageClass,omitempty"` - NoncurrentDays ExpirationDays `xml:"NoncurrentDays" json:"NoncurrentDays"` + XMLName xml.Name `xml:"NoncurrentVersionTransition,omitempty" json:"-"` + StorageClass string `xml:"StorageClass,omitempty" json:"StorageClass,omitempty"` + NoncurrentDays ExpirationDays `xml:"NoncurrentDays" json:"NoncurrentDays"` + NewerNoncurrentVersions int `xml:"NewerNoncurrentVersions,omitempty" json:"NewerNoncurrentVersions,omitempty"` } // IsDaysNull returns true if days field is null diff --git a/pkg/lifecycle/lifecycle_test.go b/pkg/lifecycle/lifecycle_test.go index 22f1719b9..365329544 100644 --- a/pkg/lifecycle/lifecycle_test.go +++ b/pkg/lifecycle/lifecycle_test.go @@ -64,7 +64,7 @@ func TestLifecycleUnmarshalJSON(t *testing.T) { "ID": "noncurrent-transition-missing", "Status": "Enabled", "NoncurrentVersionTransition": { - "Days": 0 + "NoncurrentDays": 0 } } ] @@ -78,7 +78,7 @@ func TestLifecycleUnmarshalJSON(t *testing.T) { "ID": "noncurrent-transition-missing-1", "Status": "Enabled", "NoncurrentVersionTransition": { - "Days": 1 + "NoncurrentDays": 1 } } ] @@ -108,7 +108,7 @@ func TestLifecycleUnmarshalJSON(t *testing.T) { "Status": "Enabled", "NoncurrentVersionTransition": { "StorageClass": "S3TIER-1", - "Days": 1 + "NoncurrentDays": 1 } } ] @@ -187,6 +187,19 @@ func TestLifecycleJSONRoundtrip(t *testing.T) { ID: "rule-4", Status: "Enabled", }, + { + NoncurrentVersionExpiration: NoncurrentVersionExpiration{ + NoncurrentDays: ExpirationDays(3), + NewerNoncurrentVersions: 1, + }, + NoncurrentVersionTransition: NoncurrentVersionTransition{ + NoncurrentDays: ExpirationDays(3), + NewerNoncurrentVersions: 1, + StorageClass: "MINIOTIER-2", + }, + ID: "rule-5", + Status: "Enabled", + }, }, } @@ -251,7 +264,7 @@ func TestLifecycleXMLRoundtrip(t *testing.T) { ID: "max-noncurrent-versions", Status: "Enabled", NoncurrentVersionExpiration: NoncurrentVersionExpiration{ - MaxNoncurrentVersions: 5, + NewerNoncurrentVersions: 5, }, }, },