mirror of
https://github.com/hanzoai/s3.git
synced 2026-10-30 14:59:09 +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.
127 lines
4.4 KiB
Go
127 lines
4.4 KiB
Go
package engine
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3lifecycle"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// decideMode is the per-action mode classifier the scheduler uses when
|
|
// no durable Mode exists yet. Compile tests cover most paths
|
|
// indirectly; these direct tests pin every branch so a regression in
|
|
// decideMode itself can't slip through behind a more elaborate Compile
|
|
// test failure.
|
|
|
|
func TestDecideMode_NilRuleIsDisabled(t *testing.T) {
|
|
got := decideMode(nil, s3lifecycle.ActionKindExpirationDays, 0, 0)
|
|
assert.Equal(t, ModeDisabled, got)
|
|
}
|
|
|
|
func TestDecideMode_DisabledStatusIsDisabled(t *testing.T) {
|
|
rule := &s3lifecycle.Rule{Status: s3lifecycle.StatusDisabled, ExpirationDays: 30}
|
|
got := decideMode(rule, s3lifecycle.ActionKindExpirationDays, 0, 0)
|
|
assert.Equal(t, ModeDisabled, got)
|
|
}
|
|
|
|
func TestDecideMode_ExpirationDateIsScanAtDate(t *testing.T) {
|
|
// ExpirationDate is a one-shot wall-clock trigger; no event log
|
|
// involvement, so retention gates don't apply.
|
|
rule := &s3lifecycle.Rule{
|
|
Status: s3lifecycle.StatusEnabled,
|
|
ExpirationDate: time.Now().Add(24 * time.Hour),
|
|
}
|
|
got := decideMode(rule, s3lifecycle.ActionKindExpirationDate, 0, 0)
|
|
assert.Equal(t, ModeScanAtDate, got)
|
|
}
|
|
|
|
func TestDecideMode_UnboundedRetentionIsEventDriven(t *testing.T) {
|
|
// metaLogRetention=0 means unbounded; the retention gate doesn't
|
|
// trip, so any horizon falls back to event-driven.
|
|
rule := &s3lifecycle.Rule{
|
|
Status: s3lifecycle.StatusEnabled,
|
|
ExpirationDays: 365,
|
|
}
|
|
got := decideMode(rule, s3lifecycle.ActionKindExpirationDays, 0, time.Hour)
|
|
assert.Equal(t, ModeEventDriven, got)
|
|
}
|
|
|
|
func TestDecideMode_HorizonWithinRetentionIsEventDriven(t *testing.T) {
|
|
// retention=30d, horizon=7d, lookback=1m → 7d+1m < 30d → no gate.
|
|
rule := &s3lifecycle.Rule{
|
|
Status: s3lifecycle.StatusEnabled,
|
|
ExpirationDays: 7,
|
|
}
|
|
got := decideMode(rule, s3lifecycle.ActionKindExpirationDays, 30*24*time.Hour, time.Minute)
|
|
assert.Equal(t, ModeEventDriven, got)
|
|
}
|
|
|
|
func TestDecideMode_HorizonExceedsRetentionIsScanOnly(t *testing.T) {
|
|
// retention=7d, horizon=30d → can't drive from event log alone, so
|
|
// the action is promoted to scan_only and only fires from the
|
|
// bootstrap walk.
|
|
rule := &s3lifecycle.Rule{
|
|
Status: s3lifecycle.StatusEnabled,
|
|
ExpirationDays: 30,
|
|
}
|
|
got := decideMode(rule, s3lifecycle.ActionKindExpirationDays, 7*24*time.Hour, time.Minute)
|
|
assert.Equal(t, ModeScanOnly, got)
|
|
}
|
|
|
|
func TestDecideMode_LookbackPushesAcrossThreshold(t *testing.T) {
|
|
// retention=7d, horizon=7d - the bare horizon fits, but adding the
|
|
// bootstrapLookbackMin must push it past retention so the gate
|
|
// trips. Pins that lookback is added to horizon (not retention).
|
|
rule := &s3lifecycle.Rule{
|
|
Status: s3lifecycle.StatusEnabled,
|
|
ExpirationDays: 7,
|
|
}
|
|
retention := 7 * 24 * time.Hour
|
|
// horizon already ~= retention; even a tiny lookback should trip.
|
|
got := decideMode(rule, s3lifecycle.ActionKindExpirationDays, retention, 5*time.Minute)
|
|
assert.Equal(t, ModeScanOnly, got)
|
|
}
|
|
|
|
func TestDecideMode_ZeroHorizonNeverGates(t *testing.T) {
|
|
// EventLogHorizon returns 0 for kinds whose rule fields aren't set
|
|
// (e.g. an EXPIRATION_DAYS kind on a rule with ExpirationDays=0).
|
|
// A zero horizon must skip the gate so the action falls through to
|
|
// event-driven rather than incorrectly promote to scan_only.
|
|
rule := &s3lifecycle.Rule{
|
|
Status: s3lifecycle.StatusEnabled,
|
|
// ExpirationDays unset -> EventLogHorizon returns 0
|
|
}
|
|
got := decideMode(rule, s3lifecycle.ActionKindExpirationDays, time.Hour, time.Minute)
|
|
assert.Equal(t, ModeEventDriven, got)
|
|
}
|
|
|
|
func TestRuleMode_StringRendersDocumentedNames(t *testing.T) {
|
|
// Operators read these via metrics labels and admin UI; pin the
|
|
// exact strings so a rename can't break dashboards.
|
|
cases := []struct {
|
|
mode RuleMode
|
|
want string
|
|
}{
|
|
{ModeUnspecified, "unspecified"},
|
|
{ModeEventDriven, "event_driven"},
|
|
{ModeScanAtDate, "scan_at_date"},
|
|
{ModeScanOnly, "scan_only"},
|
|
{ModeDisabled, "disabled"},
|
|
{ModePendingBootstrap, "pending_bootstrap"},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.want, func(t *testing.T) {
|
|
assert.Equal(t, c.want, c.mode.String())
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRuleMode_StringFallsToUnspecifiedForUnknown(t *testing.T) {
|
|
// A bogus enum value (e.g., a future RuleMode added without a
|
|
// String() update) must render as "unspecified" rather than empty
|
|
// or panic.
|
|
bogus := RuleMode(999)
|
|
assert.Equal(t, "unspecified", bogus.String())
|
|
}
|