mirror of
https://github.com/hanzoai/s3.git
synced 2026-11-02 13:11:24 +00:00
hanzoai/s3 was an AGPL-3.0 MinIO fork whose network-copyleft blocks embedding
and reselling as a managed service. Replace it wholesale with a fork of
SeaweedFS (github.com/seaweedfs/seaweedfs, Apache-2.0, Go) which ships a
built-in S3 gateway + Filer.
- License: AGPL-3.0 -> Apache-2.0 (upstream LICENSE kept verbatim, incl.
"Copyright 2025 Chris Lu"); NOTICE added crediting SeaweedFS. No AGPL/BUSL/
SSPL/GPL or enterprise ("ee") files remain.
- Module: go.mod path set to github.com/hanzoai/s3 with a self-replace
(replace github.com/seaweedfs/seaweedfs => ./) so the ~1800 internal Go files
keep their upstream import paths with zero churn. Internal identifiers and
import paths are intentionally NOT renamed.
- CLI rebrand: the binary is built as `s3` (was `weed`); root usage, per-command
help/usage/flag strings, shell autocomplete program name, and the product name
in CLI output now read "Hanzo S3" / `s3`. Users never see `weed`.
(e.g. `s3 server`, `s3 filer`, `s3 master`, `s3 volume`, `s3 s3`, `s3 mount`.)
- Build: `make` (or `go build -o s3 ./weed`) builds the `s3` binary green;
`cmd/weed-db` and `cmd/weed-sql` also build; `go vet ./weed/command/` clean.
- README/LLM.md rewritten for Hanzo S3; AGENTS.md/CLAUDE.md symlinks preserved.
- Dropped a 33MB prebuilt Mach-O `stress` binary upstream had committed; `.gitignore`
updated to ignore the `s3` build output.
277 lines
8.1 KiB
Go
277 lines
8.1 KiB
Go
package lifecycle_xml
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|