▍ humdrum codex / ticktock v0.0.2
license AGPL-3.0
1.1 KB raw
 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
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)
	}
}