Attach run artifacts to app notifications
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestStageNotificationEventsAndArtifactAudit(t *testing.T) {
|
||||
@@ -269,6 +270,46 @@ func TestNotificationArtifactPathSafety(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotificationArtifactSelectionAndPreview(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
public := filepath.Join(root, "9", "public")
|
||||
if err := os.MkdirAll(filepath.Join(public, "reports"), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
old := filepath.Join(public, "reports", "old.md")
|
||||
newer := filepath.Join(public, "reports", "new.md")
|
||||
if err := os.WriteFile(old, []byte("old"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(newer, []byte("# Hello world\n\n"+strings.Repeat("word ", 200)), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
oldTime := time.Now().Add(-time.Hour)
|
||||
if err := os.Chtimes(old, oldTime, oldTime); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := &runner{artifactsRoot: root}
|
||||
a, preview := r.resolveNotificationArtifact(9, 3, "reports/*.md")
|
||||
if a == nil || a.Path != "reports/new.md" || a.URL != "/artifacts/9/3/public/reports/new.md" {
|
||||
t.Fatalf("wrong selected artifact: %+v", a)
|
||||
}
|
||||
if len([]rune(preview)) > 600 || !strings.HasPrefix(preview, "Hello world") || !strings.HasSuffix(preview, "…") {
|
||||
t.Fatalf("wrong preview: %q", preview)
|
||||
}
|
||||
if got := notificationClick(9, 3, a); got != "pipelines://artifact/9/3/reports/new.md" {
|
||||
t.Fatal(got)
|
||||
}
|
||||
if got, _ := r.resolveNotificationArtifact(9, 3, ""); got != nil {
|
||||
t.Fatal("multiple files selected automatically")
|
||||
}
|
||||
if err := os.Remove(old); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, _ := r.resolveNotificationArtifact(9, 3, ""); got == nil || got.Path != "reports/new.md" {
|
||||
t.Fatal("single artifact not selected automatically")
|
||||
}
|
||||
}
|
||||
|
||||
// TestRunAttentionEventMapping pins the single decision of whether a run needs
|
||||
// the operator: a run parked on a person (waiting) or a failed run, and nothing
|
||||
// else. A queued, running, succeeded, canceled or interrupted run never notifies.
|
||||
|
||||
Reference in New Issue
Block a user