-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_test.go
More file actions
56 lines (52 loc) · 1.23 KB
/
config_test.go
File metadata and controls
56 lines (52 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// config_test.go
package main
import (
"os"
"path/filepath"
"testing"
)
func TestDefaultConfig(t *testing.T) {
cfg := DefaultConfig()
if cfg.Port != 8822 {
t.Errorf("want port 8822, got %d", cfg.Port)
}
home, _ := os.UserHomeDir()
if len(cfg.AllowedDirs) != 1 || cfg.AllowedDirs[0] != home {
t.Errorf("want AllowedDirs=[%s], got %v", home, cfg.AllowedDirs)
}
if cfg.ClaudePath != "claude" {
t.Errorf("want claude, got %s", cfg.ClaudePath)
}
}
func TestConfigSaveLoad(t *testing.T) {
dir := t.TempDir()
cfg := &Config{
Port: 9999,
AllowedDirs: []string{"/tmp"},
ClaudePath: "/usr/local/bin/claude",
DataDir: dir,
}
if err := cfg.Save(); err != nil {
t.Fatal(err)
}
loaded, err := LoadConfig(dir)
if err != nil {
t.Fatal(err)
}
if loaded.Port != 9999 {
t.Errorf("want 9999, got %d", loaded.Port)
}
if loaded.ClaudePath != "/usr/local/bin/claude" {
t.Errorf("want /usr/local/bin/claude, got %s", loaded.ClaudePath)
}
}
func TestConfigCreatesDirIfMissing(t *testing.T) {
dir := filepath.Join(t.TempDir(), "subdir")
cfg := &Config{Port: 8822, DataDir: dir}
if err := cfg.Save(); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(dir); os.IsNotExist(err) {
t.Error("expected dir to be created")
}
}