Files
s3/weed/s3api/s3lifecycle/noncurrent_since_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

76 lines
2.9 KiB
Go

package s3lifecycle
import (
"strconv"
"testing"
"time"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// Direct coverage for the parser. The router and the bootstrap walker
// both go through this single helper to read the demotion stamp, so
// pinning every parsing branch here keeps that contract enforced even
// as the call sites evolve.
func TestSuccessorFromEntryStamp_NilOrMissingReturnsZero(t *testing.T) {
assert.True(t, SuccessorFromEntryStamp(nil).IsZero())
assert.True(t, SuccessorFromEntryStamp(&filer_pb.Entry{}).IsZero())
assert.True(t, SuccessorFromEntryStamp(&filer_pb.Entry{
Extended: map[string][]byte{},
}).IsZero())
}
func TestSuccessorFromEntryStamp_EmptyOrInvalidReturnsZero(t *testing.T) {
for _, raw := range [][]byte{nil, []byte(""), []byte("nope")} {
got := SuccessorFromEntryStamp(&filer_pb.Entry{
Extended: map[string][]byte{s3_constants.ExtNoncurrentSinceNsKey: raw},
})
assert.True(t, got.IsZero(), "value %q must produce zero time", string(raw))
}
}
func TestSuccessorFromEntryStamp_NonPositiveReturnsZero(t *testing.T) {
// Stamps are wall-clock UnixNano captured at demotion time; <=0
// signals "not set" — caller falls back to derived sibling mtime.
for _, raw := range []string{"0", "-1"} {
got := SuccessorFromEntryStamp(&filer_pb.Entry{
Extended: map[string][]byte{s3_constants.ExtNoncurrentSinceNsKey: []byte(raw)},
})
assert.True(t, got.IsZero(), "value %q must produce zero time", raw)
}
}
func TestSuccessorFromEntryStamp_PositiveNanosRoundTrip(t *testing.T) {
const ns int64 = 1700000000_123456789
got := SuccessorFromEntryStamp(&filer_pb.Entry{
Extended: map[string][]byte{s3_constants.ExtNoncurrentSinceNsKey: []byte("1700000000123456789")},
})
assert.Equal(t, time.Unix(0, ns).UTC(), got.UTC())
}
func TestSuccessorFromEntryStamp_OrderedNanosStayOrdered(t *testing.T) {
// Pins the read contract: if two stamps were written in increasing
// nanosecond order, the parser must return Times in the same order.
// Uses fixed nanosecond values rather than time.Now().UnixNano() —
// UnixNano() drops the monotonic component, so back-to-back calls
// can decrease if the wall clock steps backward and the property
// being verified would then exercise OS clock behavior, not the
// parser.
require := require.New(t)
const earlier int64 = 1700000000_000000001
const later int64 = 1700000000_000000002
earlierEntry := &filer_pb.Entry{
Extended: map[string][]byte{s3_constants.ExtNoncurrentSinceNsKey: []byte(strconv.FormatInt(earlier, 10))},
}
laterEntry := &filer_pb.Entry{
Extended: map[string][]byte{s3_constants.ExtNoncurrentSinceNsKey: []byte(strconv.FormatInt(later, 10))},
}
require.False(SuccessorFromEntryStamp(earlierEntry).After(SuccessorFromEntryStamp(laterEntry)),
"parser must preserve write-order between two stamps")
}