test: покрыть файловое хранилище и описать библиотеку

This commit is contained in:
Георгий
2026-07-12 21:07:51 +03:00
parent 0ff0905a9c
commit d3be367910
2 changed files with 232 additions and 1 deletions

47
store_file_test.go Normal file
View File

@@ -0,0 +1,47 @@
package mila
import (
"context"
"path/filepath"
"testing"
)
func TestFileStorePersistsAndLoadsState(t *testing.T) {
path := filepath.Join(t.TempDir(), "bvk_content.json")
ctx := context.Background()
first := NewFileStore(path)
state := 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)
}
if got.UpdatedAt.IsZero() != state.UpdatedAt.IsZero() {
t.Fatalf("unexpected updated_at value: %s", got.UpdatedAt)
}
}
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 err != ErrNotReady {
t.Fatalf("expected ErrNotReady, got %v", err)
}
}