feat: add command domain invariants
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
rvboxv1 "github.com/rvbox/rvbox/gen/go/rvbox/v1"
|
||||
)
|
||||
|
||||
func TestEventSequenceAndDuplicateEquivalence_HP_CLIENT_07(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
first := FingerprintBytes([]byte("first"))
|
||||
other := FingerprintBytes([]byte("other"))
|
||||
if decision, err := ClassifyEventSequence(0, 1, nil, first); err != nil || decision != EventSequenceAppend {
|
||||
t.Fatalf("first event = (%v, %v)", decision, err)
|
||||
}
|
||||
if decision, err := ClassifyEventSequence(1, 1, &first, first); err != nil || decision != EventSequenceDuplicate {
|
||||
t.Fatalf("exact duplicate = (%v, %v)", decision, err)
|
||||
}
|
||||
if _, err := ClassifyEventSequence(1, 1, &first, other); !errors.Is(err, ErrConflictingDuplicate) {
|
||||
t.Fatalf("conflicting duplicate error = %v", err)
|
||||
}
|
||||
if _, err := ClassifyEventSequence(1, 1, nil, first); !errors.Is(err, ErrMissingDuplicate) {
|
||||
t.Fatalf("missing duplicate error = %v", err)
|
||||
}
|
||||
if _, err := ClassifyEventSequence(1, 3, nil, first); !errors.Is(err, ErrEventSequenceGap) {
|
||||
t.Fatalf("gap error = %v", err)
|
||||
}
|
||||
if _, err := ClassifyEventSequence(0, 0, nil, first); !errors.Is(err, ErrInvalidEventSequence) {
|
||||
t.Fatalf("zero sequence error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutputTruncationRanges_HP_PROTO_01(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
one, two := uint64(1), uint64(2)
|
||||
zero := uint64(0)
|
||||
tests := []struct {
|
||||
name string
|
||||
value *rvboxv1.OutputTruncation
|
||||
valid bool
|
||||
}{
|
||||
{"client pre-sequence loss", &rvboxv1.OutputTruncation{}, true},
|
||||
{"server range", &rvboxv1.OutputTruncation{FirstRemovedEventSeq: &one, LastRemovedEventSeq: &two}, true},
|
||||
{"nil", nil, false},
|
||||
{"first only", &rvboxv1.OutputTruncation{FirstRemovedEventSeq: &one}, false},
|
||||
{"last only", &rvboxv1.OutputTruncation{LastRemovedEventSeq: &two}, false},
|
||||
{"zero", &rvboxv1.OutputTruncation{FirstRemovedEventSeq: &zero, LastRemovedEventSeq: &two}, false},
|
||||
{"reversed", &rvboxv1.OutputTruncation{FirstRemovedEventSeq: &two, LastRemovedEventSeq: &one}, false},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := ValidateOutputTruncation(test.value)
|
||||
if (err == nil) != test.valid {
|
||||
t.Fatalf("ValidateOutputTruncation() error = %v, valid = %t", err, test.valid)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user