49 lines
1.8 KiB
Go
49 lines
1.8 KiB
Go
package spool
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestCheckSpoolPayloadsAndCounters_HP_CLIENT_09(t *testing.T) {
|
|
t.Parallel()
|
|
ctx := context.Background()
|
|
store := openTestStore(t, ctx, filepath.Join(t.TempDir(), "spool"), DefaultTombstoneLimit)
|
|
issue := testUUID(t, "019c46f1-1d02-7000-8000-000000000041")
|
|
if _, err := store.AcceptCommand(ctx, testCommand(issue, []byte("recovery")), time.Now().UTC()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := store.AppendEvent(ctx, issue, EventInput{Kind: 1, Compression: 1, Payload: []byte("durable event"), CreatedAt: time.Now().UTC()}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
report, err := store.Check(ctx)
|
|
if err != nil || report.EventsChecked != 1 || report.ScriptsChecked != 0 {
|
|
t.Fatalf("initial Check = %#v, %v", report, err)
|
|
}
|
|
if _, err := store.db.ExecContext(ctx, `UPDATE events SET payload = ? WHERE issue_uuid = ?`, []byte("tampered"), issue[:]); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := store.Check(ctx); !errors.Is(err, ErrStoredPayloadChecksum) {
|
|
t.Fatalf("tampered event Check error = %v, want ErrStoredPayloadChecksum", err)
|
|
}
|
|
}
|
|
|
|
func TestCheckSpoolRejectsCounterDrift_BH_CLIENT_03(t *testing.T) {
|
|
t.Parallel()
|
|
ctx := context.Background()
|
|
store := openTestStore(t, ctx, filepath.Join(t.TempDir(), "spool"), DefaultTombstoneLimit)
|
|
issue := testUUID(t, "019c46f1-1d02-7000-8000-000000000042")
|
|
if _, err := store.AcceptCommand(ctx, testCommand(issue, []byte("recovery")), time.Now().UTC()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := store.db.ExecContext(ctx, `UPDATE spool_counters SET client_total_charged_bytes = client_total_charged_bytes + 1`); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := store.Check(ctx); !errors.Is(err, ErrQuotaCounterMismatch) {
|
|
t.Fatalf("counter-drift Check error = %v, want ErrQuotaCounterMismatch", err)
|
|
}
|
|
}
|