yaju-is-always-watching-you/internal/config/config_test.go
awayatan f411886d88
Some checks are pending
CI / test (push) Waiting to run
Split phrase list out into community-editable phrases.yaml
config.yaml previously mixed secrets with the phrase list, forcing
private-only edits. Now config supports phrases_file, which is loaded and
merged with any private phrases: entries, so the repo-tracked phrases.yaml
can be extended via PR while per-deployment additions stay private.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-26 23:27:27 +09:00

55 lines
1.3 KiB
Go

package config
import (
"os"
"path/filepath"
"reflect"
"testing"
)
func writeFile(t *testing.T, path, content string) {
t.Helper()
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
t.Fatalf("write %s: %v", path, err)
}
}
func TestLoad_PhrasesFileMergesWithInline(t *testing.T) {
dir := t.TempDir()
writeFile(t, filepath.Join(dir, "phrases.yaml"), "phrases:\n - しょうもな\n - たまげたなあ\n")
writeFile(t, filepath.Join(dir, "config.yaml"), `
listen_addr: ":8080"
webhook_secret: "s"
forgejo:
base_url: "http://forgejo:3000"
token: "t"
phrases_file: "./phrases.yaml"
phrases:
- 独自の追加語録
`)
cfg, err := Load(filepath.Join(dir, "config.yaml"))
if err != nil {
t.Fatalf("Load() error = %v", err)
}
want := []string{"しょうもな", "たまげたなあ", "独自の追加語録"}
if !reflect.DeepEqual(cfg.Phrases, want) {
t.Fatalf("Phrases = %v, want %v", cfg.Phrases, want)
}
}
func TestLoad_MissingPhrasesIsError(t *testing.T) {
dir := t.TempDir()
writeFile(t, filepath.Join(dir, "config.yaml"), `
webhook_secret: "s"
forgejo:
base_url: "http://forgejo:3000"
token: "t"
`)
if _, err := Load(filepath.Join(dir, "config.yaml")); err == nil {
t.Fatal("Load() error = nil, want error for empty phrases")
}
}