69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
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)
|
|
}
|
|
})
|
|
}
|
|
}
|