Make configuration truthful and clean remote session files

This commit is contained in:
2026-08-10 21:41:00 +00:00
parent 72a200968a
commit 32653f54f9
32 changed files with 395 additions and 72 deletions

View File

@@ -0,0 +1,68 @@
package config
import (
"strings"
"testing"
)
func TestNotificationConfigSupportsOnlyNoopMode(t *testing.T) {
tests := []struct {
name string
section string
wantLoad string
wantValidate string
}{
{
name: "default noop mode",
section: "",
},
{
name: "explicit noop mode",
section: "notification:\n mode: noop\n",
},
{
name: "backend is rejected",
section: "notification:\n backend: email\n",
wantLoad: "field backend not found",
},
{
name: "recipient is rejected",
section: "notification:\n recipient: party@example.com\n",
wantLoad: "field recipient not found",
},
{
name: "provider mode is rejected",
section: "notification:\n mode: email\n",
wantValidate: "pipeline.notification.mode must be \"noop\"",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pipelinePath, sessionPath := writeConfigFiles(t, testPipelineBaseYAML+"\n"+tt.section, testSessionBaseYAML)
cfg, err := Load(pipelinePath, sessionPath)
if tt.wantLoad != "" {
if err == nil || !strings.Contains(err.Error(), tt.wantLoad) {
t.Fatalf("Load() error = %v, want %q", err, tt.wantLoad)
}
return
}
if err != nil {
t.Fatalf("Load() error = %v", err)
}
if got := cfg.Pipeline.Notification.Mode; tt.wantValidate == "" && got != DefaultNotificationMode {
t.Fatalf("notification.mode = %q, want %q", got, DefaultNotificationMode)
}
err = Validate(cfg)
if tt.wantValidate != "" {
if err == nil || !strings.Contains(err.Error(), tt.wantValidate) {
t.Fatalf("Validate() error = %v, want %q", err, tt.wantValidate)
}
return
}
if err != nil {
t.Fatalf("Validate() error = %v", err)
}
})
}
}