48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"gitea.unprism.ru/KRBL/mila/protocol"
|
|
)
|
|
|
|
func TestFileStorePersistsAndLoadsState(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "bvk_content.json")
|
|
ctx := context.Background()
|
|
|
|
first := NewFileStore(path)
|
|
state := protocol.ContentState{
|
|
Route: "3",
|
|
Text: "Гостиный двор",
|
|
Template: "main",
|
|
}
|
|
if err := first.Set(ctx, state); err != nil {
|
|
t.Fatalf("set state: %v", err)
|
|
}
|
|
|
|
second := NewFileStore(path)
|
|
got, err := second.Get(ctx)
|
|
if err != nil {
|
|
t.Fatalf("get state: %v", err)
|
|
}
|
|
|
|
if got.Route != state.Route || got.Text != state.Text || got.Template != state.Template {
|
|
t.Fatalf("unexpected state: %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestFileStoreMissingFileReturnsNotReady(t *testing.T) {
|
|
store := NewFileStore(filepath.Join(t.TempDir(), "missing.json"))
|
|
|
|
_, err := store.Get(context.Background())
|
|
if err == nil {
|
|
t.Fatal("expected error")
|
|
}
|
|
if !errors.Is(err, protocol.ErrNotReady) {
|
|
t.Fatalf("expected ErrNotReady, got %v", err)
|
|
}
|
|
}
|