Files
antidrift/internal/store/store_test.go
T
felixm 63247e402a Add snapshot store
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-31 11:43:31 -04:00

51 lines
1.4 KiB
Go

package store
import (
"path/filepath"
"testing"
"time"
"antidrift/internal/domain"
)
func TestLoadMissingFileReturnsLocked(t *testing.T) {
path := filepath.Join(t.TempDir(), "state.json")
s, err := Load(path)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if s.RuntimeState != domain.RuntimeLocked {
t.Errorf("missing file should be Locked, got %s", s.RuntimeState)
}
if s.Commitment != nil {
t.Errorf("missing file should have nil commitment")
}
}
func TestSaveThenLoadRoundTrips(t *testing.T) {
path := filepath.Join(t.TempDir(), "nested", "state.json")
c, _ := domain.NewManual("Port store", "store tests pass", 25*time.Minute)
c.State = domain.CommitmentActive
want := Snapshot{
RuntimeState: domain.RuntimeActive,
Commitment: &c,
DeadlineUnixSecs: 1748725200,
}
if err := Save(path, want); err != nil {
t.Fatalf("save failed: %v", err)
}
got, err := Load(path)
if err != nil {
t.Fatalf("load failed: %v", err)
}
if got.RuntimeState != want.RuntimeState {
t.Errorf("runtime state: got %s want %s", got.RuntimeState, want.RuntimeState)
}
if got.Commitment == nil || got.Commitment.NextAction != "Port store" {
t.Errorf("commitment did not round-trip: %+v", got.Commitment)
}
if got.DeadlineUnixSecs != want.DeadlineUnixSecs {
t.Errorf("deadline: got %d want %d", got.DeadlineUnixSecs, want.DeadlineUnixSecs)
}
}