package config import ( "os" "path/filepath" "testing" ) func TestDefault(t *testing.T) { c := Default() if c.SlotMinutes != 30 || c.GridStart != "07:00" || c.GridEnd != "21:00" || c.Project != "" { t.Fatalf("bad defaults: %+v", c) } } func TestLoadFromMissingFileReturnsDefaults(t *testing.T) { c := LoadFrom(filepath.Join(t.TempDir(), "nope.json")) if c != Default() { t.Fatalf("missing file should give defaults, got %+v", c) } } func TestLoadFromMergesAndClampsSlot(t *testing.T) { dir := t.TempDir() p := filepath.Join(dir, "config.json") if err := os.WriteFile(p, []byte(`{"slot_minutes":2,"grid_start":"06:00","project":"ARCHER"}`), 0o644); err != nil { t.Fatal(err) } c := LoadFrom(p) if c.SlotMinutes != 5 { // clamped up from 2 t.Errorf("slot=%d, want 5", c.SlotMinutes) } if c.GridStart != "06:00" { t.Errorf("grid_start=%q, want 06:00", c.GridStart) } if c.GridEnd != "21:00" { // untouched key keeps default t.Errorf("grid_end=%q, want 21:00", c.GridEnd) } if c.Project != "ARCHER" { t.Errorf("project=%q, want ARCHER", c.Project) } }