- go.mod with github.com/dailz/go-kv, Go 1.26.3, testify - config/config.go with WalConfig, Validate() with checked arithmetic - errors.go with sentinel errors (ErrCommitUnknown, ErrWriteStopped, etc.) - wal/constants.go with all WAL format constants and enums - wal/header.go with WAL File Header encode/decode (CRC32 IEEE) - wal/record.go with Physical Record codec, block boundary, SplitIntoRecords - wal/entry.go with WAL Entry codec (varint keys/values, OpType, ValueKind) - wal/sequence.go with SequenceManager (atomic, CAS, overflow-safe) - manifest/manifest.go with MANIFEST stub (Load/Save atomic) - manifest/current.go with CURRENT file (WriteCurrent/ReadCurrent) - Comprehensive tests for all modules - .golangci.yml configuration
43 lines
918 B
Go
43 lines
918 B
Go
package go_kv
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestErrorTypes(t *testing.T) {
|
|
allErrors := []error{
|
|
ErrCommitUnknown,
|
|
ErrWriteStopped,
|
|
ErrSequenceExhausted,
|
|
ErrWALCorrupted,
|
|
ErrInvalidConfig,
|
|
}
|
|
|
|
// Each error must match itself via errors.Is.
|
|
for _, err := range allErrors {
|
|
if !errors.Is(err, err) {
|
|
t.Errorf("errors.Is(%v, %v) = false, want true", err, err)
|
|
}
|
|
}
|
|
|
|
// Each error must NOT match any other error.
|
|
for i, a := range allErrors {
|
|
for j, b := range allErrors {
|
|
if i == j {
|
|
continue
|
|
}
|
|
if errors.Is(a, b) {
|
|
t.Errorf("errors.Is(%v, %v) = true, want false (distinct errors)", a, b)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Wrapped errors must still be identifiable via errors.Is.
|
|
wrapped := fmt.Errorf("operation failed: %w", ErrCommitUnknown)
|
|
if !errors.Is(wrapped, ErrCommitUnknown) {
|
|
t.Errorf("errors.Is(wrapped ErrCommitUnknown, ErrCommitUnknown) = false, want true")
|
|
}
|
|
}
|