39 lines
904 B
Go
39 lines
904 B
Go
package feichibridge
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestStateStorePersistsAcknowledgedCursor(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "nested", "state.json")
|
|
store, err := OpenStateStore(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
at := time.Date(2026, 7, 17, 12, 0, 0, 0, time.UTC)
|
|
if err := store.CommitRealtime("LTEST32960VIN0001", at, "hash"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := store.CommitBackfill("LTEST32960VIN0001", at.Add(-time.Minute)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
reopened, err := OpenStateStore(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := reopened.Vehicle("LTEST32960VIN0001")
|
|
if !got.LastRealtimeTime.Equal(at) || got.LastRealtimeHash != "hash" {
|
|
t.Fatalf("state = %#v", got)
|
|
}
|
|
info, err := os.Stat(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if info.Mode().Perm() != 0o600 {
|
|
t.Fatalf("state mode = %o", info.Mode().Perm())
|
|
}
|
|
}
|