|
| 1 | +package profile |
| 2 | + |
| 3 | +import ( |
| 4 | + "path/filepath" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +func TestLoadExpandsTildePaths(t *testing.T) { |
| 9 | + home := t.TempDir() |
| 10 | + t.Setenv("HOME", home) |
| 11 | + t.Setenv("XDG_CONFIG_HOME", t.TempDir()) |
| 12 | + |
| 13 | + inst := "~/instances/foo" |
| 14 | + cache := "~/cache/mods" |
| 15 | + logf := "~/logs/run.log" |
| 16 | + p := &Profile{InstanceDir: &inst, CacheDir: &cache, LogFile: &logf} |
| 17 | + if err := Save("tilde", p); err != nil { |
| 18 | + t.Fatalf("Save: %v", err) |
| 19 | + } |
| 20 | + |
| 21 | + got, err := Load("tilde") |
| 22 | + if err != nil { |
| 23 | + t.Fatalf("Load: %v", err) |
| 24 | + } |
| 25 | + |
| 26 | + wantInst := filepath.Join(home, "instances", "foo") |
| 27 | + if got.InstanceDir == nil || *got.InstanceDir != wantInst { |
| 28 | + t.Errorf("InstanceDir = %v, want %q", got.InstanceDir, wantInst) |
| 29 | + } |
| 30 | + wantCache := filepath.Join(home, "cache", "mods") |
| 31 | + if got.CacheDir == nil || *got.CacheDir != wantCache { |
| 32 | + t.Errorf("CacheDir = %v, want %q", got.CacheDir, wantCache) |
| 33 | + } |
| 34 | + wantLog := filepath.Join(home, "logs", "run.log") |
| 35 | + if got.LogFile == nil || *got.LogFile != wantLog { |
| 36 | + t.Errorf("LogFile = %v, want %q", got.LogFile, wantLog) |
| 37 | + } |
| 38 | +} |
0 commit comments