Files
mtusi2026lab6/internal/pipeline/cleanup_test.go
T

50 lines
1.3 KiB
Go

package pipeline
import (
"context"
"testing"
)
type cleanupFixture struct {
claimErr error
removeErr error
confirmErr error
}
// ExpireStaging supplies one safely claimed source key.
func (f cleanupFixture) ExpireStaging(context.Context) ([]string, error) {
return []string{"staging/claimed"}, f.claimErr
}
// Remove injects an independent deletion acknowledgement outcome.
func (f cleanupFixture) Remove(context.Context, string) error {
return f.removeErr
}
// StagingRemoved injects acknowledgement persistence failure.
func (f cleanupFixture) StagingRemoved(context.Context, string) error {
return f.confirmErr
}
// TestCleanupBoundaries verifies deletion is counted only after both acknowledgements.
func TestCleanupBoundaries(t *testing.T) {
for _, tc := range []struct {
name string
fixture cleanupFixture
want int
failed bool
}{
{"claim failed", cleanupFixture{claimErr: errInjected}, 0, true},
{"delete failed", cleanupFixture{removeErr: errInjected}, 0, true},
{"confirm failed", cleanupFixture{confirmErr: errInjected}, 0, true},
{"completed", cleanupFixture{}, 1, false},
} {
t.Run(tc.name, func(t *testing.T) {
count, err := Cleanup(t.Context(), tc.fixture, tc.fixture)
if count != tc.want || (err != nil) != tc.failed {
t.Fatalf("cleanup: %d %v", count, err)
}
})
}
}