Files
seaweedfs/weed/s3api/s3lifecycle/final_cleanup_test.go
Chris LuandGitHub 2840980c7d test(s3/lifecycle): final unit-test cleanup before integration suite (#9414)
* test(s3/lifecycle): final unit-test cleanup before integration suite

Closes the residual coverage gaps in the lifecycle packages so the
next track (Layer 3 integration tests) starts from a clean baseline.
Big coverage lifts: lifecycletest 88.7→100.0, engine 81.7→95.1,
s3lifecycle 87.8→95.0, dispatcher 60.3→67.6, router 86.1→88.8,
bootstrap 90.7→92.6. Remaining sub-100% surfaces (reader.Run,
Pipeline.Run, scheduler.Run, multi-step bootstrap orchestration)
need a live filer and belong with the integration suite.

router/helpers_test.go (formerly #9409, now stale on master because
9410-9413 absorbed adjacent surface): direct tests for the pure
helpers Route exercises indirectly — successorModTimeFromContainer
(missing/empty/non-numeric/non-positive/positive round-trip),
logicalKeyFromVersionPath (extracts logical, rejects non-.versions
parent / root-level / no-slashes / bare container), isVersionsContainerKey
(table over container forms), isVersionFolderPath (table over child
forms), isDeleteMarkerEntry (only literal "true" matches),
extractTags (nil/empty, AmzObjectTagging-prefixed only, no-tag
returns nil), hasActiveEventDrivenAction (matches only active+
event-driven, scan-only rejected, unknown skipped). Plus engine
Snapshot accessors: BucketVersioned (compiled flag, unknown bucket
false), BucketActionKeys (full list, unknown nil), Action (unknown
nil), AllActions (every kind), SnapshotID (strictly monotonic).

s3lifecycle/final_cleanup_test.go: ActionKind.String default branch
(unspecified + future-unknown render "unspecified" rather than
empty); HashExtended direct from the lifecycle package (covers it
in this package's coverage report, not just the s3api one) including
nil/empty produces no bytes and identical content hashes the same.

bootstrap/has_prefix_test.go: thin wrapper around strings.HasPrefix
exported by the package; trivial but at 0% pre-fix.

lifecycletest/eventbuilder_old_entry_test.go: pins the OldEntry
fall-through path on Delete events for WithModTime / WithTtlSec /
WithVersionID / WithExtended / WithChunks (existing tests cover
Create events that hit NewEntry only). Adds WithBootstrapVersion
across all three event shapes. Defensive: every With* option is a
no-op on a degenerate event with neither entry populated.

* test(s3/lifecycle): address coderabbit nitpicks on final cleanup

- eventbuilder empty-event test now exercises WithBootstrapVersion
  too, with an honest claim about its scope: it targets the event
  itself (not an entry), so it sets BootstrapVersion regardless of
  whether NewEntry/OldEntry are populated. Renamed the test from
  AllAreNoOpsOnEmptyEvent to NoPanicOnEmptyEvent since the original
  name overstated the contract.
- HashExtended stability check uses a 3-key map with different
  literal orders so the helper's sort path actually does work; a
  single-key check can't catch an iteration-order regression.
- HasPrefix test refactored to table-driven so adding a new edge
  case is one row instead of two assertion lines.
2026-05-09 22:32:49 -07:00

49 lines
1.8 KiB
Go

package s3lifecycle
import (
"testing"
"github.com/stretchr/testify/assert"
)
// Final unit-test cleanup ahead of the integration suite. Pins the
// remaining 0%-and-default-branch helpers in the s3lifecycle package
// and the lifecycletest builder so a regression doesn't slip in
// during the integration work that follows.
func TestActionKind_StringUnspecifiedDefault(t *testing.T) {
// String's default branch (covers ActionKindUnspecified and any
// future enum value not listed) must render "unspecified" rather
// than empty or panic. Operators read this via the metrics labels
// (see S3LifecycleDispatchCounter "kind").
assert.Equal(t, "unspecified", ActionKindUnspecified.String())
assert.Equal(t, "unspecified", ActionKind(99).String())
}
func TestHashExtended_DirectFromLifecyclePackage(t *testing.T) {
// HashExtended is exercised from the s3api package's identity
// tests; pin it here so the s3lifecycle package's own coverage
// reflects the call. A nil/empty map produces no bytes, so the
// CAS witness collapses to "no Extended" rather than a synthetic
// hash that would mismatch on the server.
assert.Empty(t, HashExtended(nil))
assert.Empty(t, HashExtended(map[string][]byte{}))
got := HashExtended(map[string][]byte{"a": []byte("1")})
assert.NotEmpty(t, got)
// Same content, different literal/insertion order across multiple
// keys: hash must be stable. A single-key check can't catch an
// iteration-order regression — multiple keys force the helper's
// sort path to actually do work.
first := HashExtended(map[string][]byte{
"a": []byte("1"),
"b": []byte("2"),
"c": []byte("3"),
})
second := HashExtended(map[string][]byte{
"c": []byte("3"),
"a": []byte("1"),
"b": []byte("2"),
})
assert.Equal(t, first, second, "hash must be insensitive to map iteration order")
}