Files
s3/weed/s3api/s3lifecycle/action_kind_test.go
zooqueen dd74d3e6d6 Replace AGPL MinIO fork with Apache-2.0 SeaweedFS fork; rebrand CLI weed->s3
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.
2026-06-18 23:41:25 -07:00

87 lines
3.0 KiB
Go

package s3lifecycle
import (
"reflect"
"testing"
)
func TestRuleActionKinds_SingleAction(t *testing.T) {
cases := []struct {
name string
rule *Rule
want []ActionKind
}{
{"expiration_days", &Rule{ExpirationDays: 30}, []ActionKind{ActionKindExpirationDays}},
{"expiration_date", &Rule{ExpirationDate: mustTime(t, "2025-06-15T00:00:00Z")}, []ActionKind{ActionKindExpirationDate}},
{"expired_delete_marker", &Rule{ExpiredObjectDeleteMarker: true}, []ActionKind{ActionKindExpiredDeleteMarker}},
{"noncurrent_days", &Rule{NoncurrentVersionExpirationDays: 30}, []ActionKind{ActionKindNoncurrentDays}},
{"newer_noncurrent_alone", &Rule{NewerNoncurrentVersions: 3}, []ActionKind{ActionKindNewerNoncurrent}},
{"abort_mpu", &Rule{AbortMPUDaysAfterInitiation: 7}, []ActionKind{ActionKindAbortMPU}},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if got := RuleActionKinds(c.rule); !reflect.DeepEqual(got, c.want) {
t.Fatalf("want %v, got %v", c.want, got)
}
})
}
}
func TestRuleActionKinds_MultiAction(t *testing.T) {
// The bug this fixes: a single XML <Rule> can declare ExpirationDays,
// AbortMPU, and NoncurrentDays in parallel. Each must compile to its
// own action with its own delay group / mode / pending — not be
// collapsed into one entry whose delay is the smallest.
rule := &Rule{
ExpirationDays: 90,
AbortMPUDaysAfterInitiation: 7,
NoncurrentVersionExpirationDays: 30,
}
want := []ActionKind{
ActionKindExpirationDays,
ActionKindNoncurrentDays,
ActionKindAbortMPU,
}
if got := RuleActionKinds(rule); !reflect.DeepEqual(got, want) {
t.Fatalf("want %v, got %v", want, got)
}
}
func TestRuleActionKinds_NoncurrentDaysSubsumesNewerNoncurrent(t *testing.T) {
// When both NoncurrentDays and NewerNoncurrent are set on the same rule,
// they are AWS-paired conditions for ONE noncurrent expiration action,
// not two; only NoncurrentDays is emitted.
rule := &Rule{NoncurrentVersionExpirationDays: 30, NewerNoncurrentVersions: 3}
want := []ActionKind{ActionKindNoncurrentDays}
if got := RuleActionKinds(rule); !reflect.DeepEqual(got, want) {
t.Fatalf("want %v, got %v", want, got)
}
}
func TestRuleActionKinds_Empty(t *testing.T) {
if got := RuleActionKinds(&Rule{}); len(got) != 0 {
t.Fatalf("want empty, got %v", got)
}
if got := RuleActionKinds(nil); got != nil {
t.Fatalf("want nil, got %v", got)
}
}
func TestActionKind_StringIsStable(t *testing.T) {
// The string is the leaf-directory name on disk; renaming would
// orphan existing state, so pin the values.
cases := map[ActionKind]string{
ActionKindExpirationDays: "expiration_days",
ActionKindExpirationDate: "expiration_date",
ActionKindNoncurrentDays: "noncurrent_days",
ActionKindNewerNoncurrent: "newer_noncurrent",
ActionKindAbortMPU: "abort_mpu",
ActionKindExpiredDeleteMarker: "expired_delete_marker",
}
for k, want := range cases {
if got := k.String(); got != want {
t.Fatalf("ActionKind(%d).String() = %q, want %q", k, got, want)
}
}
}