package paths import ( "path/filepath" "strings" "testing" ) func TestDataDirEnvWins(t *testing.T) { // The override is what lets one machine run two instances, and what makes // the installed layout testable from a checkout - on both sides. dir := t.TempDir() t.Setenv("BEHAVISION_DATA_DIR", dir) if got := StateRoot(); got != dir { t.Fatalf("StateRoot() = %q, want %q", got, dir) } } func TestEverythingLivesUnderTheStateRoot(t *testing.T) { dir := t.TempDir() t.Setenv("BEHAVISION_DATA_DIR", dir) for name, got := range map[string]string{ "agent config": AgentConfig(), "spool": SpoolDir(), "engine log": EngineLog(), "credentials": APICredentials(), } { if !strings.HasPrefix(got, dir) { t.Errorf("%s resolved outside the state root: %s", name, got) } } } func TestEnsureStateIsIdempotent(t *testing.T) { dir := filepath.Join(t.TempDir(), "fresh") t.Setenv("BEHAVISION_DATA_DIR", dir) if err := EnsureState(); err != nil { t.Fatal(err) } if err := EnsureState(); err != nil { t.Fatalf("second call failed: %v", err) } }