69 lines
2.3 KiB
Go
69 lines
2.3 KiB
Go
package app
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestResolveSessionConfigPathWithCandidatesExplicitWins(t *testing.T) {
|
|
got, err := resolveSessionConfigPathWithCandidates(" ./custom/session.yml ", []string{"./session.yml", "/a", "/b"})
|
|
if err != nil {
|
|
t.Fatalf("resolveSessionConfigPathWithCandidates() error = %v", err)
|
|
}
|
|
if got != "./custom/session.yml" {
|
|
t.Fatalf("resolved path = %q, want explicit path", got)
|
|
}
|
|
}
|
|
|
|
func TestResolveSessionConfigPathWithCandidatesUsesFirstExisting(t *testing.T) {
|
|
dir := t.TempDir()
|
|
first := filepath.Join(dir, "first.yml")
|
|
second := filepath.Join(dir, "second.yml")
|
|
if err := os.WriteFile(second, []byte("session_id: 2026-05-03\n"), 0o644); err != nil {
|
|
t.Fatalf("write second default: %v", err)
|
|
}
|
|
|
|
got, err := resolveSessionConfigPathWithCandidates("", []string{first, second})
|
|
if err != nil {
|
|
t.Fatalf("resolveSessionConfigPathWithCandidates() error = %v", err)
|
|
}
|
|
if got != filepath.Clean(second) {
|
|
t.Fatalf("resolved path = %q, want %q", got, filepath.Clean(second))
|
|
}
|
|
}
|
|
|
|
func TestResolveSessionConfigPathWithCandidatesPrecedence(t *testing.T) {
|
|
dir := t.TempDir()
|
|
first := filepath.Join(dir, "first.yml")
|
|
second := filepath.Join(dir, "second.yml")
|
|
if err := os.WriteFile(first, []byte("session_id: 2026-05-03\n"), 0o644); err != nil {
|
|
t.Fatalf("write first default: %v", err)
|
|
}
|
|
if err := os.WriteFile(second, []byte("session_id: 2026-05-03\n"), 0o644); err != nil {
|
|
t.Fatalf("write second default: %v", err)
|
|
}
|
|
|
|
got, err := resolveSessionConfigPathWithCandidates("", []string{first, second})
|
|
if err != nil {
|
|
t.Fatalf("resolveSessionConfigPathWithCandidates() error = %v", err)
|
|
}
|
|
if got != filepath.Clean(first) {
|
|
t.Fatalf("resolved path = %q, want first candidate %q", got, filepath.Clean(first))
|
|
}
|
|
}
|
|
|
|
func TestResolveSessionConfigPathWithCandidatesMissing(t *testing.T) {
|
|
_, err := resolveSessionConfigPathWithCandidates("", []string{"/does/not/exist/one.yml", "/does/not/exist/two.yml"})
|
|
if err == nil {
|
|
t.Fatal("expected error, got nil")
|
|
}
|
|
if !strings.Contains(err.Error(), "no default session config found") {
|
|
t.Fatalf("error = %q, want missing-defaults context", err.Error())
|
|
}
|
|
if !strings.Contains(err.Error(), "pass --session") {
|
|
t.Fatalf("error = %q, want explicit-path guidance", err.Error())
|
|
}
|
|
}
|