f5f31b7bcd
A stage's notify block may name `link=<pattern>` (validated like `open=`). When the hook fires, the newest public/ match is read (at most 4 KiB); its first non-empty line, if an absolute http(s) URL ntfy accepts as a click, becomes the ntfy Click and the app notification click, with the run kept as the app's run action and ntfy's browser view. A missing file or invalid URL keeps today's tap target and is noted on the receipt diagnostic. Android opens such an http(s) click in the browser (after clearing the notification) instead of handing it to Flutter as a route.
46 lines
2.5 KiB
Go
46 lines
2.5 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=success\nopen=reports/*.md", true}, {"on=success\nopen=/secret", false}, {"on=success\nopen=../secret", false}, {"on=success\nopen=.secret", false}, {"on=success\nopen=[", false},
|
|
{"on=success\nlink=standup-link.txt", true}, {"on=success\nlink=links/*.txt\nopen=reports/*.md", true}, {"on=success\nlink=/secret", false}, {"on=success\nlink=../secret", false}, {"on=success\nlink=.secret", false}, {"on=success\nlink=a//b", false}, {"on=success\nlink=[", false}, {"on=success\nlink=a.txt\nlink=b.txt", false},
|
|
{"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 := strings.Replace(Template([]string{"one"}, true), "# stage one", "# stage one\n```notify\non=success\nlink=standup-link.txt\nopen=*.md\n```", 1)
|
|
// `pipelines validate` uses this report parser.
|
|
if graph, _, err := ParseDefinitionReport(source); err != nil || graph.Stages[0].Notify.Link != "standup-link.txt" || graph.Stages[0].Notify.Open != "*.md" {
|
|
t.Fatal("notify link not validated", err)
|
|
}
|
|
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)
|
|
}
|
|
}
|