39 lines
1.6 KiB
Go
39 lines
1.6 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestNotifyPolicyParsing(t *testing.T) {
|
|
for _, test := range []struct {
|
|
text string
|
|
valid bool
|
|
}{
|
|
{"on=success\ndestination=anime", true}, {"on=failure\ndestination=anime\nartifacts=files", true}, {"on=success,failure\ndestination=anime\nartifacts=markdown,files", true},
|
|
{"on=error\ndestination=anime", false}, {"on=success,success\ndestination=anime", false}, {"destination=anime", false}, {"on=success", true}, {"on=failure\nartifacts=markdown,files", true}, {"on=success\ndestination=../secret", false}, {"on=success\ndestination=anime\ntoken=secret", false}, {"on=success\ndestination=anime\nartifacts=*", false}, {"on=success\non=failure\ndestination=anime", false},
|
|
} {
|
|
source := strings.Replace(Template([]string{"one"}, true), "# stage one", "# stage one\n```notify\n"+test.text+"\n```", 1)
|
|
graph, err := Parse(source)
|
|
if (err == nil) != test.valid {
|
|
t.Fatalf("notify %q: %v", test.text, err)
|
|
}
|
|
if err == nil {
|
|
s := graph.Stages[0]
|
|
if s.Notify == nil {
|
|
t.Fatal("notify lost")
|
|
}
|
|
if s.Notify.Destination != "system" {
|
|
t.Fatal("notification is not system-wide", s.Notify)
|
|
}
|
|
if _, exists := StageDefinition(s).Blocks["notify"]; exists {
|
|
t.Fatal("common notify block passed to model validator")
|
|
}
|
|
}
|
|
}
|
|
source := "# stage native\n```configs\ntype=ntfy\ndestination=anime\n```\n```notify\non=failure\ndestination=anime\n```\n```edges\nsuccess -> #success\nerror -> #failure\n```"
|
|
if _, err := Parse(source); err != nil {
|
|
t.Fatal("notify not supported on native stage", err)
|
|
}
|
|
}
|