snapshot of https://github.com/seaweedfs/seaweedfs.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
This commit is contained in:
599
weed/s3api/lifecycle_xml/round_trip_test.go
Normal file
599
weed/s3api/lifecycle_xml/round_trip_test.go
Normal file
@@ -0,0 +1,599 @@
|
||||
package lifecycle_xml
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3lifecycle"
|
||||
)
|
||||
|
||||
func TestLifecycleXMLRoundTrip_NoncurrentVersionExpiration(t *testing.T) {
|
||||
input := `<LifecycleConfiguration>
|
||||
<Rule>
|
||||
<ID>expire-noncurrent</ID>
|
||||
<Status>Enabled</Status>
|
||||
<Filter><Prefix></Prefix></Filter>
|
||||
<NoncurrentVersionExpiration>
|
||||
<NoncurrentDays>30</NoncurrentDays>
|
||||
<NewerNoncurrentVersions>2</NewerNoncurrentVersions>
|
||||
</NoncurrentVersionExpiration>
|
||||
</Rule>
|
||||
</LifecycleConfiguration>`
|
||||
|
||||
var lc Lifecycle
|
||||
if err := xml.Unmarshal([]byte(input), &lc); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
|
||||
if len(lc.Rules) != 1 {
|
||||
t.Fatalf("expected 1 rule, got %d", len(lc.Rules))
|
||||
}
|
||||
rule := lc.Rules[0]
|
||||
if rule.ID != "expire-noncurrent" {
|
||||
t.Errorf("expected ID 'expire-noncurrent', got %q", rule.ID)
|
||||
}
|
||||
if rule.NoncurrentVersionExpiration.NoncurrentDays != 30 {
|
||||
t.Errorf("expected NoncurrentDays=30, got %d", rule.NoncurrentVersionExpiration.NoncurrentDays)
|
||||
}
|
||||
if rule.NoncurrentVersionExpiration.NewerNoncurrentVersions != 2 {
|
||||
t.Errorf("expected NewerNoncurrentVersions=2, got %d", rule.NoncurrentVersionExpiration.NewerNoncurrentVersions)
|
||||
}
|
||||
|
||||
// Re-marshal and verify it round-trips.
|
||||
out, err := xml.Marshal(lc)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal: %v", err)
|
||||
}
|
||||
s := string(out)
|
||||
if !strings.Contains(s, "<NoncurrentDays>30</NoncurrentDays>") {
|
||||
t.Errorf("marshaled XML missing NoncurrentDays: %s", s)
|
||||
}
|
||||
if !strings.Contains(s, "<NewerNoncurrentVersions>2</NewerNoncurrentVersions>") {
|
||||
t.Errorf("marshaled XML missing NewerNoncurrentVersions: %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLifecycleXMLRoundTrip_AbortIncompleteMultipartUpload(t *testing.T) {
|
||||
input := `<LifecycleConfiguration>
|
||||
<Rule>
|
||||
<ID>abort-mpu</ID>
|
||||
<Status>Enabled</Status>
|
||||
<Filter><Prefix></Prefix></Filter>
|
||||
<AbortIncompleteMultipartUpload>
|
||||
<DaysAfterInitiation>7</DaysAfterInitiation>
|
||||
</AbortIncompleteMultipartUpload>
|
||||
</Rule>
|
||||
</LifecycleConfiguration>`
|
||||
|
||||
var lc Lifecycle
|
||||
if err := xml.Unmarshal([]byte(input), &lc); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
|
||||
rule := lc.Rules[0]
|
||||
if rule.AbortIncompleteMultipartUpload.DaysAfterInitiation != 7 {
|
||||
t.Errorf("expected DaysAfterInitiation=7, got %d", rule.AbortIncompleteMultipartUpload.DaysAfterInitiation)
|
||||
}
|
||||
|
||||
out, err := xml.Marshal(lc)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(out), "<DaysAfterInitiation>7</DaysAfterInitiation>") {
|
||||
t.Errorf("marshaled XML missing DaysAfterInitiation: %s", string(out))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLifecycleXMLRoundTrip_FilterWithTag(t *testing.T) {
|
||||
input := `<LifecycleConfiguration>
|
||||
<Rule>
|
||||
<ID>tag-filter</ID>
|
||||
<Status>Enabled</Status>
|
||||
<Filter>
|
||||
<Tag><Key>env</Key><Value>dev</Value></Tag>
|
||||
</Filter>
|
||||
<Expiration><Days>7</Days></Expiration>
|
||||
</Rule>
|
||||
</LifecycleConfiguration>`
|
||||
|
||||
var lc Lifecycle
|
||||
if err := xml.Unmarshal([]byte(input), &lc); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
|
||||
rule := lc.Rules[0]
|
||||
if !rule.Filter.TagSet() {
|
||||
t.Error("expected Filter.TagSet() to be true")
|
||||
}
|
||||
if rule.Filter.Tag.Key != "env" || rule.Filter.Tag.Value != "dev" {
|
||||
t.Errorf("expected Tag{env:dev}, got Tag{%s:%s}", rule.Filter.Tag.Key, rule.Filter.Tag.Value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLifecycleXMLRoundTrip_FilterWithAnd(t *testing.T) {
|
||||
input := `<LifecycleConfiguration>
|
||||
<Rule>
|
||||
<ID>and-filter</ID>
|
||||
<Status>Enabled</Status>
|
||||
<Filter>
|
||||
<And>
|
||||
<Prefix>logs/</Prefix>
|
||||
<Tag><Key>env</Key><Value>dev</Value></Tag>
|
||||
<Tag><Key>tier</Key><Value>hot</Value></Tag>
|
||||
<ObjectSizeGreaterThan>1024</ObjectSizeGreaterThan>
|
||||
<ObjectSizeLessThan>1048576</ObjectSizeLessThan>
|
||||
</And>
|
||||
</Filter>
|
||||
<Expiration><Days>7</Days></Expiration>
|
||||
</Rule>
|
||||
</LifecycleConfiguration>`
|
||||
|
||||
var lc Lifecycle
|
||||
if err := xml.Unmarshal([]byte(input), &lc); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
|
||||
rule := lc.Rules[0]
|
||||
if !rule.Filter.AndSet() {
|
||||
t.Error("expected Filter.AndSet() to be true")
|
||||
}
|
||||
if rule.Filter.And.Prefix.String() != "logs/" {
|
||||
t.Errorf("expected And.Prefix='logs/', got %q", rule.Filter.And.Prefix.String())
|
||||
}
|
||||
if len(rule.Filter.And.Tags) != 2 {
|
||||
t.Fatalf("expected 2 And tags, got %d", len(rule.Filter.And.Tags))
|
||||
}
|
||||
if rule.Filter.And.ObjectSizeGreaterThan != 1024 {
|
||||
t.Errorf("expected ObjectSizeGreaterThan=1024, got %d", rule.Filter.And.ObjectSizeGreaterThan)
|
||||
}
|
||||
if rule.Filter.And.ObjectSizeLessThan != 1048576 {
|
||||
t.Errorf("expected ObjectSizeLessThan=1048576, got %d", rule.Filter.And.ObjectSizeLessThan)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLifecycleXMLRoundTrip_FilterWithSizeOnly(t *testing.T) {
|
||||
input := `<LifecycleConfiguration>
|
||||
<Rule>
|
||||
<ID>size-filter</ID>
|
||||
<Status>Enabled</Status>
|
||||
<Filter>
|
||||
<ObjectSizeGreaterThan>512</ObjectSizeGreaterThan>
|
||||
<ObjectSizeLessThan>10485760</ObjectSizeLessThan>
|
||||
</Filter>
|
||||
<Expiration><Days>30</Days></Expiration>
|
||||
</Rule>
|
||||
</LifecycleConfiguration>`
|
||||
|
||||
var lc Lifecycle
|
||||
if err := xml.Unmarshal([]byte(input), &lc); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
|
||||
rule := lc.Rules[0]
|
||||
if rule.Filter.ObjectSizeGreaterThan != 512 {
|
||||
t.Errorf("expected ObjectSizeGreaterThan=512, got %d", rule.Filter.ObjectSizeGreaterThan)
|
||||
}
|
||||
if rule.Filter.ObjectSizeLessThan != 10485760 {
|
||||
t.Errorf("expected ObjectSizeLessThan=10485760, got %d", rule.Filter.ObjectSizeLessThan)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLifecycleXML_TransitionSetFlag(t *testing.T) {
|
||||
// Verify that Transition.Set() is true after unmarshaling.
|
||||
input := `<LifecycleConfiguration>
|
||||
<Rule>
|
||||
<ID>transition</ID>
|
||||
<Status>Enabled</Status>
|
||||
<Filter><Prefix></Prefix></Filter>
|
||||
<Transition>
|
||||
<Days>30</Days>
|
||||
<StorageClass>GLACIER</StorageClass>
|
||||
</Transition>
|
||||
</Rule>
|
||||
</LifecycleConfiguration>`
|
||||
|
||||
var lc Lifecycle
|
||||
if err := xml.Unmarshal([]byte(input), &lc); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
if !lc.Rules[0].Transition.Set() {
|
||||
t.Error("expected Transition.Set()=true after unmarshal")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLifecycleXML_NoncurrentVersionTransitionSetFlag(t *testing.T) {
|
||||
input := `<LifecycleConfiguration>
|
||||
<Rule>
|
||||
<ID>nv-transition</ID>
|
||||
<Status>Enabled</Status>
|
||||
<Filter><Prefix></Prefix></Filter>
|
||||
<NoncurrentVersionTransition>
|
||||
<NoncurrentDays>60</NoncurrentDays>
|
||||
<StorageClass>GLACIER</StorageClass>
|
||||
</NoncurrentVersionTransition>
|
||||
</Rule>
|
||||
</LifecycleConfiguration>`
|
||||
|
||||
var lc Lifecycle
|
||||
if err := xml.Unmarshal([]byte(input), &lc); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
if !lc.Rules[0].NoncurrentVersionTransition.Set() {
|
||||
t.Error("expected NoncurrentVersionTransition.Set()=true after unmarshal")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLifecycleXMLRoundTrip_CompleteRule(t *testing.T) {
|
||||
// A complete lifecycle config similar to what Terraform sends.
|
||||
input := `<LifecycleConfiguration>
|
||||
<Rule>
|
||||
<ID>rotation</ID>
|
||||
<Filter><Prefix></Prefix></Filter>
|
||||
<Status>Enabled</Status>
|
||||
<Expiration><Days>30</Days></Expiration>
|
||||
<NoncurrentVersionExpiration>
|
||||
<NoncurrentDays>1</NoncurrentDays>
|
||||
</NoncurrentVersionExpiration>
|
||||
<AbortIncompleteMultipartUpload>
|
||||
<DaysAfterInitiation>1</DaysAfterInitiation>
|
||||
</AbortIncompleteMultipartUpload>
|
||||
</Rule>
|
||||
</LifecycleConfiguration>`
|
||||
|
||||
var lc Lifecycle
|
||||
if err := xml.Unmarshal([]byte(input), &lc); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
|
||||
rule := lc.Rules[0]
|
||||
if rule.ID != "rotation" {
|
||||
t.Errorf("expected ID 'rotation', got %q", rule.ID)
|
||||
}
|
||||
if rule.Expiration.Days != 30 {
|
||||
t.Errorf("expected Expiration.Days=30, got %d", rule.Expiration.Days)
|
||||
}
|
||||
if rule.NoncurrentVersionExpiration.NoncurrentDays != 1 {
|
||||
t.Errorf("expected NoncurrentDays=1, got %d", rule.NoncurrentVersionExpiration.NoncurrentDays)
|
||||
}
|
||||
if rule.AbortIncompleteMultipartUpload.DaysAfterInitiation != 1 {
|
||||
t.Errorf("expected DaysAfterInitiation=1, got %d", rule.AbortIncompleteMultipartUpload.DaysAfterInitiation)
|
||||
}
|
||||
|
||||
// Re-marshal and verify all fields survive.
|
||||
out, err := xml.Marshal(lc)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal: %v", err)
|
||||
}
|
||||
s := string(out)
|
||||
for _, expected := range []string{
|
||||
"<Days>30</Days>",
|
||||
"<NoncurrentDays>1</NoncurrentDays>",
|
||||
"<DaysAfterInitiation>1</DaysAfterInitiation>",
|
||||
} {
|
||||
if !strings.Contains(s, expected) {
|
||||
t.Errorf("marshaled XML missing %q: %s", expected, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// assertCanonicalRoundTrip drives a canonical rule through
|
||||
// CanonicalToLifecycle -> MarshalCanonical -> ParseCanonical and checks the
|
||||
// result matches the input, proving the admin write path (which only ever
|
||||
// has the canonical form) produces XML the S3 API can read back unchanged.
|
||||
func assertCanonicalRoundTrip(t *testing.T, in *s3lifecycle.Rule) *s3lifecycle.Rule {
|
||||
t.Helper()
|
||||
|
||||
xmlBytes, err := MarshalCanonical([]*s3lifecycle.Rule{in})
|
||||
if err != nil {
|
||||
t.Fatalf("MarshalCanonical: %v", err)
|
||||
}
|
||||
|
||||
out, err := ParseCanonical(xmlBytes)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseCanonical(%s): %v", xmlBytes, err)
|
||||
}
|
||||
if len(out) != 1 {
|
||||
t.Fatalf("expected 1 rule after round trip, got %d: %s", len(out), xmlBytes)
|
||||
}
|
||||
return out[0]
|
||||
}
|
||||
|
||||
func TestCanonicalRoundTrip_WholeBucket(t *testing.T) {
|
||||
in := &s3lifecycle.Rule{ID: "whole-bucket", Status: s3lifecycle.StatusEnabled, ExpirationDays: 30}
|
||||
out := assertCanonicalRoundTrip(t, in)
|
||||
if out.Prefix != "" {
|
||||
t.Errorf("expected empty prefix, got %q", out.Prefix)
|
||||
}
|
||||
if out.ExpirationDays != 30 {
|
||||
t.Errorf("expected ExpirationDays=30, got %d", out.ExpirationDays)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalRoundTrip_PrefixOnly(t *testing.T) {
|
||||
in := &s3lifecycle.Rule{ID: "prefix-only", Status: s3lifecycle.StatusEnabled, Prefix: "logs/", ExpirationDays: 7}
|
||||
out := assertCanonicalRoundTrip(t, in)
|
||||
if out.Prefix != "logs/" {
|
||||
t.Errorf("expected prefix 'logs/', got %q", out.Prefix)
|
||||
}
|
||||
if len(out.FilterTags) != 0 {
|
||||
t.Errorf("expected no tags, got %v", out.FilterTags)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalRoundTrip_TagOnly(t *testing.T) {
|
||||
in := &s3lifecycle.Rule{
|
||||
ID: "tag-only",
|
||||
Status: s3lifecycle.StatusEnabled,
|
||||
FilterTags: map[string]string{"env": "dev"},
|
||||
ExpirationDays: 7,
|
||||
}
|
||||
out := assertCanonicalRoundTrip(t, in)
|
||||
if out.Prefix != "" {
|
||||
t.Errorf("expected empty prefix, got %q", out.Prefix)
|
||||
}
|
||||
if len(out.FilterTags) != 1 || out.FilterTags["env"] != "dev" {
|
||||
t.Errorf("expected tags {env:dev}, got %v", out.FilterTags)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalRoundTrip_PrefixAndTags(t *testing.T) {
|
||||
in := &s3lifecycle.Rule{
|
||||
ID: "prefix-and-tags",
|
||||
Status: s3lifecycle.StatusEnabled,
|
||||
Prefix: "logs/",
|
||||
FilterTags: map[string]string{"env": "dev", "tier": "hot"},
|
||||
ExpirationDays: 7,
|
||||
}
|
||||
out := assertCanonicalRoundTrip(t, in)
|
||||
if out.Prefix != "logs/" {
|
||||
t.Errorf("expected prefix 'logs/', got %q", out.Prefix)
|
||||
}
|
||||
if len(out.FilterTags) != 2 || out.FilterTags["env"] != "dev" || out.FilterTags["tier"] != "hot" {
|
||||
t.Errorf("expected tags {env:dev, tier:hot}, got %v", out.FilterTags)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalRoundTrip_SizeBounds(t *testing.T) {
|
||||
in := &s3lifecycle.Rule{
|
||||
ID: "size-bounds",
|
||||
Status: s3lifecycle.StatusEnabled,
|
||||
FilterSizeGreaterThan: 512,
|
||||
FilterSizeLessThan: 1048576,
|
||||
ExpirationDays: 30,
|
||||
}
|
||||
out := assertCanonicalRoundTrip(t, in)
|
||||
if out.FilterSizeGreaterThan != 512 {
|
||||
t.Errorf("expected FilterSizeGreaterThan=512, got %d", out.FilterSizeGreaterThan)
|
||||
}
|
||||
if out.FilterSizeLessThan != 1048576 {
|
||||
t.Errorf("expected FilterSizeLessThan=1048576, got %d", out.FilterSizeLessThan)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalRoundTrip_PrefixAndTagsWithSizeBounds(t *testing.T) {
|
||||
// Multiple discriminants (prefix + tags) force the <And> branch, which
|
||||
// carries its own size bounds distinct from the single-branch Filter.
|
||||
in := &s3lifecycle.Rule{
|
||||
ID: "and-with-size",
|
||||
Status: s3lifecycle.StatusEnabled,
|
||||
Prefix: "logs/",
|
||||
FilterTags: map[string]string{"env": "dev"},
|
||||
FilterSizeGreaterThan: 1024,
|
||||
FilterSizeLessThan: 2048,
|
||||
ExpirationDays: 7,
|
||||
}
|
||||
out := assertCanonicalRoundTrip(t, in)
|
||||
if out.Prefix != "logs/" || len(out.FilterTags) != 1 {
|
||||
t.Errorf("expected prefix 'logs/' and 1 tag, got prefix=%q tags=%v", out.Prefix, out.FilterTags)
|
||||
}
|
||||
if out.FilterSizeGreaterThan != 1024 || out.FilterSizeLessThan != 2048 {
|
||||
t.Errorf("expected size bounds 1024/2048, got %d/%d", out.FilterSizeGreaterThan, out.FilterSizeLessThan)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalRoundTrip_ExpirationDate(t *testing.T) {
|
||||
date := time.Date(2030, 1, 15, 0, 0, 0, 0, time.UTC)
|
||||
in := &s3lifecycle.Rule{ID: "expire-on-date", Status: s3lifecycle.StatusEnabled, ExpirationDate: date}
|
||||
out := assertCanonicalRoundTrip(t, in)
|
||||
if !out.ExpirationDate.Equal(date) {
|
||||
t.Errorf("expected ExpirationDate=%v, got %v", date, out.ExpirationDate)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalRoundTrip_ExpiredObjectDeleteMarker(t *testing.T) {
|
||||
in := &s3lifecycle.Rule{ID: "delete-marker", Status: s3lifecycle.StatusEnabled, ExpiredObjectDeleteMarker: true}
|
||||
out := assertCanonicalRoundTrip(t, in)
|
||||
if !out.ExpiredObjectDeleteMarker {
|
||||
t.Error("expected ExpiredObjectDeleteMarker=true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalRoundTrip_NoncurrentVersionExpiration(t *testing.T) {
|
||||
in := &s3lifecycle.Rule{
|
||||
ID: "noncurrent",
|
||||
Status: s3lifecycle.StatusEnabled,
|
||||
NoncurrentVersionExpirationDays: 30,
|
||||
NewerNoncurrentVersions: 2,
|
||||
}
|
||||
out := assertCanonicalRoundTrip(t, in)
|
||||
if out.NoncurrentVersionExpirationDays != 30 {
|
||||
t.Errorf("expected NoncurrentVersionExpirationDays=30, got %d", out.NoncurrentVersionExpirationDays)
|
||||
}
|
||||
if out.NewerNoncurrentVersions != 2 {
|
||||
t.Errorf("expected NewerNoncurrentVersions=2, got %d", out.NewerNoncurrentVersions)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalRoundTrip_AbortMultipartUpload(t *testing.T) {
|
||||
in := &s3lifecycle.Rule{ID: "abort-mpu", Status: s3lifecycle.StatusEnabled, AbortMPUDaysAfterInitiation: 7}
|
||||
out := assertCanonicalRoundTrip(t, in)
|
||||
if out.AbortMPUDaysAfterInitiation != 7 {
|
||||
t.Errorf("expected AbortMPUDaysAfterInitiation=7, got %d", out.AbortMPUDaysAfterInitiation)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalRoundTrip_Disabled(t *testing.T) {
|
||||
in := &s3lifecycle.Rule{ID: "disabled-rule", Status: s3lifecycle.StatusDisabled, ExpirationDays: 30}
|
||||
out := assertCanonicalRoundTrip(t, in)
|
||||
if out.Status != s3lifecycle.StatusDisabled {
|
||||
t.Errorf("expected Status=Disabled, got %q", out.Status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalRoundTrip_TagOrderIsStable(t *testing.T) {
|
||||
// FilterTags is a map; And.Tags must be emitted in a deterministic
|
||||
// (sorted) order so re-saving an unchanged rule doesn't churn the
|
||||
// stored XML.
|
||||
in := &s3lifecycle.Rule{
|
||||
ID: "stable-order",
|
||||
Status: s3lifecycle.StatusEnabled,
|
||||
Prefix: "logs/",
|
||||
FilterTags: map[string]string{"zeta": "1", "alpha": "2", "mu": "3"},
|
||||
}
|
||||
|
||||
var firstXML []byte
|
||||
for i := 0; i < 5; i++ {
|
||||
xmlBytes, err := MarshalCanonical([]*s3lifecycle.Rule{in})
|
||||
if err != nil {
|
||||
t.Fatalf("MarshalCanonical: %v", err)
|
||||
}
|
||||
if i == 0 {
|
||||
firstXML = xmlBytes
|
||||
continue
|
||||
}
|
||||
if string(xmlBytes) != string(firstXML) {
|
||||
t.Fatalf("marshal output is not stable across runs:\n%s\nvs\n%s", firstXML, xmlBytes)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(string(firstXML), "<Tag><Key>alpha</Key>") {
|
||||
t.Errorf("expected tags sorted alphabetically (alpha first), got: %s", firstXML)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalRoundTrip_PrefixWithSizeBoundsUsesAnd(t *testing.T) {
|
||||
// A size range paired with a prefix is two different attributes, which
|
||||
// requires <And> — unlike a size range alone (see
|
||||
// TestCanonicalRoundTrip_SizeBounds), which doesn't need one.
|
||||
in := &s3lifecycle.Rule{
|
||||
ID: "prefix-with-size",
|
||||
Status: s3lifecycle.StatusEnabled,
|
||||
Prefix: "logs/",
|
||||
FilterSizeGreaterThan: 1024,
|
||||
ExpirationDays: 7,
|
||||
}
|
||||
|
||||
xmlBytes, err := MarshalCanonical([]*s3lifecycle.Rule{in})
|
||||
if err != nil {
|
||||
t.Fatalf("MarshalCanonical: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(xmlBytes), "<And>") {
|
||||
t.Errorf("expected prefix+size to be wrapped in <And>, got: %s", xmlBytes)
|
||||
}
|
||||
|
||||
out := assertCanonicalRoundTrip(t, in)
|
||||
if out.Prefix != "logs/" {
|
||||
t.Errorf("expected prefix 'logs/', got %q", out.Prefix)
|
||||
}
|
||||
if out.FilterSizeGreaterThan != 1024 {
|
||||
t.Errorf("expected FilterSizeGreaterThan=1024, got %d", out.FilterSizeGreaterThan)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalRoundTrip_TagWithSizeBoundsUsesAnd(t *testing.T) {
|
||||
in := &s3lifecycle.Rule{
|
||||
ID: "tag-with-size",
|
||||
Status: s3lifecycle.StatusEnabled,
|
||||
FilterTags: map[string]string{"env": "dev"},
|
||||
FilterSizeLessThan: 2048,
|
||||
ExpirationDays: 7,
|
||||
}
|
||||
|
||||
xmlBytes, err := MarshalCanonical([]*s3lifecycle.Rule{in})
|
||||
if err != nil {
|
||||
t.Fatalf("MarshalCanonical: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(xmlBytes), "<And>") {
|
||||
t.Errorf("expected tag+size to be wrapped in <And>, got: %s", xmlBytes)
|
||||
}
|
||||
|
||||
out := assertCanonicalRoundTrip(t, in)
|
||||
if len(out.FilterTags) != 1 || out.FilterTags["env"] != "dev" {
|
||||
t.Errorf("expected tags {env:dev}, got %v", out.FilterTags)
|
||||
}
|
||||
if out.FilterSizeLessThan != 2048 {
|
||||
t.Errorf("expected FilterSizeLessThan=2048, got %d", out.FilterSizeLessThan)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalRoundTrip_SizeOnlyOmitsPrefixElement(t *testing.T) {
|
||||
// A size-only filter must not stamp a spurious empty <Prefix> — nothing
|
||||
// was requested, so nothing besides the size bounds should appear.
|
||||
in := &s3lifecycle.Rule{
|
||||
ID: "size-only-no-prefix",
|
||||
Status: s3lifecycle.StatusEnabled,
|
||||
FilterSizeGreaterThan: 512,
|
||||
ExpirationDays: 7,
|
||||
}
|
||||
|
||||
xmlBytes, err := MarshalCanonical([]*s3lifecycle.Rule{in})
|
||||
if err != nil {
|
||||
t.Fatalf("MarshalCanonical: %v", err)
|
||||
}
|
||||
if strings.Contains(string(xmlBytes), "<Prefix>") {
|
||||
t.Errorf("expected no <Prefix> element for a size-only filter, got: %s", xmlBytes)
|
||||
}
|
||||
|
||||
out := assertCanonicalRoundTrip(t, in)
|
||||
if out.Prefix != "" {
|
||||
t.Errorf("expected empty prefix, got %q", out.Prefix)
|
||||
}
|
||||
if out.FilterSizeGreaterThan != 512 {
|
||||
t.Errorf("expected FilterSizeGreaterThan=512, got %d", out.FilterSizeGreaterThan)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalRoundTrip_SizeRangeUsesAnd(t *testing.T) {
|
||||
// <Filter> holds one predicate; a range is two, so it belongs under <And>,
|
||||
// which is the form AWS documents.
|
||||
in := &s3lifecycle.Rule{
|
||||
ID: "size-range",
|
||||
Status: s3lifecycle.StatusEnabled,
|
||||
FilterSizeGreaterThan: 512,
|
||||
FilterSizeLessThan: 1048576,
|
||||
ExpirationDays: 30,
|
||||
}
|
||||
|
||||
xmlBytes, err := MarshalCanonical([]*s3lifecycle.Rule{in})
|
||||
if err != nil {
|
||||
t.Fatalf("MarshalCanonical: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(xmlBytes), "<And><ObjectSizeGreaterThan>512</ObjectSizeGreaterThan><ObjectSizeLessThan>1048576</ObjectSizeLessThan></And>") {
|
||||
t.Errorf("expected both size bounds under <And>, got: %s", xmlBytes)
|
||||
}
|
||||
|
||||
out := assertCanonicalRoundTrip(t, in)
|
||||
if out.FilterSizeGreaterThan != 512 || out.FilterSizeLessThan != 1048576 {
|
||||
t.Errorf("expected the size range to survive the round trip, got %+v", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarshalCanonical_CarriesTheS3Namespace(t *testing.T) {
|
||||
// GetBucketLifecycleConfiguration replays these bytes verbatim, so a
|
||||
// document written here has to look like one a client PUT.
|
||||
xmlBytes, err := MarshalCanonical([]*s3lifecycle.Rule{{
|
||||
ID: "ns",
|
||||
Status: s3lifecycle.StatusEnabled,
|
||||
ExpirationDays: 1,
|
||||
}})
|
||||
if err != nil {
|
||||
t.Fatalf("MarshalCanonical: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(xmlBytes), `<LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">`) {
|
||||
t.Errorf("expected the S3 namespace on the root element, got: %s", xmlBytes)
|
||||
}
|
||||
if _, err := ParseCanonical(xmlBytes); err != nil {
|
||||
t.Errorf("the namespaced document must still parse: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user