Files
2dph/bin/watch/watch_test.go
T
eSliderandGitHub 20b78a9a20
Tests / Test (push) Failing after 5s
Tests / Release (semver) (push) Skipped
feat: brain/index.go shebang; mail import is not a brain write (D14). (#12)
Commands live at bin/brain/{index,get,stats,eval,watch}.go and
bin/mail/import.go, bin/markdown/import.go, bin/postgres/query.go.
Python remains the Ladybug write worker. index_mail is a deprecation
shim that rebuilds via --with-mail.
2026-08-13 17:46:25 +01:00

54 lines
1.4 KiB
Go

package watch
import (
"os"
"path/filepath"
"strings"
"testing"
"time"
)
func TestStampChangesWhenFileTouched(t *testing.T) {
dir := t.TempDir()
a := filepath.Join(dir, "a.md")
if err := os.WriteFile(a, []byte("x"), 0o644); err != nil {
t.Fatal(err)
}
s1 := Stamp([]string{dir})
if s1 == "" {
t.Fatal("stamp empty for a dir with a file")
}
time.Sleep(10 * time.Millisecond)
if err := os.WriteFile(a, []byte("y"), 0o644); err != nil {
t.Fatal(err)
}
if s2 := Stamp([]string{dir}); s2 == s1 {
t.Fatal("stamp did not change after the file was modified")
}
}
func TestStampEmptyForMissingDir(t *testing.T) {
if s := Stamp([]string{filepath.Join(t.TempDir(), "nope")}); s != "" {
t.Fatalf("stamp = %q, want empty for missing dir", s)
}
}
func TestFromEnvDefaults(t *testing.T) {
t.Setenv("KB_WATCH_INTERVAL", "")
t.Setenv("KB_WATCH_DIRS", "")
t.Setenv("KB_PY", "")
opts := fromEnv(nil)
if len(opts.Dirs) == 0 || opts.Dirs[0] != "/corpus" {
t.Fatalf("default dirs = %v, want [/corpus]", opts.Dirs)
}
if opts.Interval != 30*time.Second {
t.Fatalf("default interval = %s, want 30s", opts.Interval)
}
if !strings.Contains(opts.IndexCmd, "kb/index") {
t.Fatalf("default index cmd = %q, want kb/index", opts.IndexCmd)
}
if !strings.Contains(opts.IndexCmd, "--with-mail") {
t.Fatalf("default index cmd must include --with-mail, got %q", opts.IndexCmd)
}
}