64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package cc
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestListClaudeProfiles_basic(t *testing.T) {
|
|
dir := t.TempDir()
|
|
for _, name := range []string{"beta.json", "alpha.json", "gamma.json"} {
|
|
if err := os.WriteFile(filepath.Join(dir, name), []byte("{}"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
// non-.json files should be ignored
|
|
if err := os.WriteFile(filepath.Join(dir, "readme.txt"), []byte("x"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// subdirs should be ignored
|
|
if err := os.Mkdir(filepath.Join(dir, "subdir"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
profiles, err := ListClaudeProfiles(dir)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if len(profiles) != 3 {
|
|
t.Fatalf("want 3 profiles, got %d", len(profiles))
|
|
}
|
|
wantNames := []string{"alpha", "beta", "gamma"}
|
|
for i, p := range profiles {
|
|
if p.Name != wantNames[i] {
|
|
t.Errorf("profiles[%d].Name = %q, want %q", i, p.Name, wantNames[i])
|
|
}
|
|
wantPath := filepath.Join(dir, wantNames[i]+".json")
|
|
if p.Path != wantPath {
|
|
t.Errorf("profiles[%d].Path = %q, want %q", i, p.Path, wantPath)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestListClaudeProfiles_emptyDir(t *testing.T) {
|
|
dir := t.TempDir()
|
|
profiles, err := ListClaudeProfiles(dir)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if len(profiles) != 0 {
|
|
t.Fatalf("want 0 profiles, got %d", len(profiles))
|
|
}
|
|
}
|
|
|
|
func TestListClaudeProfiles_missingDir(t *testing.T) {
|
|
profiles, err := ListClaudeProfiles("/nonexistent/path/does/not/exist")
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if len(profiles) != 0 {
|
|
t.Fatalf("want 0 profiles, got %d", len(profiles))
|
|
}
|
|
}
|