Review fixes: recorder Flush without panic; unreadable config file is an error

Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
This commit is contained in:
2026-09-25 02:58:17 -07:00
parent 74e7d4895b
commit 9e0f906c8b
4 changed files with 117 additions and 1 deletions
+47
View File
@@ -0,0 +1,47 @@
package config_test
import (
"os"
"path/filepath"
"strings"
"testing"
"git.wntrmute.dev/kyle/crossbar/internal/config"
)
// A file that exists but cannot be read is an error, and not a validation error: nothing about
// the configuration has been judged. Only a missing file is "absent" (and that is an error too).
func TestUnreadableFileIsAnError(t *testing.T) {
if os.Geteuid() == 0 {
t.Skip("root can read a 000 file")
}
dir := t.TempDir()
path := filepath.Join(dir, "crossbar.toml")
good, err := os.ReadFile(filepath.Join("testdata", "good.toml"))
if err != nil {
t.Fatal(err)
}
if err := os.WriteFile(path, good, 0o000); err != nil {
t.Fatal(err)
}
_, err = config.Load(path)
if err == nil {
t.Fatal("Load on an unreadable file must fail")
}
if _, ok := config.IsError(err); ok {
t.Errorf("an unreadable file is not a validation *Error: %v", err)
}
if !strings.HasPrefix(err.Error(), "config: ") {
t.Errorf("Error() = %q, want the config: prefix", err.Error())
}
}
func TestDirectoryIsAnError(t *testing.T) {
_, err := config.Load(t.TempDir())
if err == nil {
t.Fatal("Load on a directory must fail")
}
if _, ok := config.IsError(err); ok {
t.Errorf("a directory is not a validation *Error: %v", err)
}
}