package cli import ( "bytes" "os" "path/filepath" "strings" "testing" ) func TestRunCalNewAndCheck(t *testing.T) { dir := t.TempDir() t.Setenv("LECTIO_CONFIG", filepath.Join(dir, "config.ini")) var buf bytes.Buffer if code := runCalNew("krakow", &buf, &buf); code != 0 { t.Fatalf("cal-new exit %d: %s", code, buf.String()) } path := filepath.Join(dir, "calendars", "krakow.ini") if _, err := os.Stat(path); err != nil { t.Fatal("scaffold not written") } // the scaffold must validate clean buf.Reset() if code := runCalCheck("krakow", &buf, &buf); code != 0 { t.Fatalf("cal-check on scaffold exit %d: %s", code, buf.String()) } if !strings.Contains(buf.String(), "ok:") { t.Errorf("expected ok, got: %s", buf.String()) } // refuse to overwrite buf.Reset() if code := runCalNew("krakow", &buf, &buf); code == 0 { t.Error("cal-new should refuse to overwrite an existing file") } } func TestRunCalCheckReportsBadFields(t *testing.T) { dir := t.TempDir() t.Setenv("LECTIO_CONFIG", filepath.Join(dir, "config.ini")) os.MkdirAll(filepath.Join(dir, "calendars"), 0o755) os.WriteFile(filepath.Join(dir, "calendars", "bad.ini"), []byte("[layer]\nid = bad\n\n[x]\ndate = 99-99\nrank = archfeast\ncolour = teal\n"), 0o644) var buf bytes.Buffer if code := runCalCheck("bad", &buf, &buf); code == 0 { t.Fatalf("cal-check should fail on bad fields:\n%s", buf.String()) } out := buf.String() for _, want := range []string{"date", "rank", "colour"} { if !strings.Contains(out, want) { t.Errorf("expected a %s problem reported:\n%s", want, out) } } }