A test run pins a validated draft, runs with forge and push writes suppressed and recorded per step, and is excluded from workflow stats. The History tab lists revisions that changed a workflow, diffs them as YAML and on the canvas, restores into the editor, and ties runs to the revision they used.
44 lines
1.6 KiB
Go
44 lines
1.6 KiB
Go
package workflow
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/events"
|
|
)
|
|
|
|
// TestSuppressForgeWritesSkipsEveryWrite pins that a test run reaches neither
|
|
// the forge nor a push: the embedded nil Forger and Trees panic if any call
|
|
// falls through, and each skipped write is recorded as an event.
|
|
func TestSuppressForgeWritesSkipsEveryWrite(t *testing.T) {
|
|
bus := events.NewBus()
|
|
sub := bus.Subscribe(16)
|
|
defer sub.Close()
|
|
tc := &TaskContext{Task: &Task{Source: SourceTest, Owner: "o", Repo: "r"}, Bus: bus, Stage: "open-pr"}
|
|
SuppressForgeWrites(tc)
|
|
|
|
ctx := context.Background()
|
|
writes := map[string]func() error{
|
|
"close": func() error { return tc.Forge.CloseIssue(ctx, "o", "r", 1, "") },
|
|
"pr": func() error { _, err := tc.Forge.CreatePR(ctx, "o", "r", "t", "h", "b", ""); return err },
|
|
"link": func() error { return tc.Forge.LinkBranch(ctx, "o", "r", 1, "br") },
|
|
"review": func() error { return tc.Forge.CreateReviewComments(ctx, "o", "r", 1, "", nil) },
|
|
"comment": func() error { _, err := tc.Forge.Comment(ctx, "o", "r", 1, "hi"); return err },
|
|
"reply": func() error { return tc.Forge.ReplyToReview(ctx, "o", "r", 1, 2, "hi") },
|
|
"push": func() error { return tc.Trees.Push(ctx, "dir", "br") },
|
|
}
|
|
for name, write := range writes {
|
|
if err := write(); err != nil {
|
|
t.Fatalf("%s: %v", name, err)
|
|
}
|
|
select {
|
|
case event := <-sub.C:
|
|
if event.Kind != events.KindForgeSuppressed || event.Stage != "open-pr" || event.Detail == "" {
|
|
t.Fatalf("%s recorded %+v", name, event)
|
|
}
|
|
default:
|
|
t.Fatalf("%s was not recorded", name)
|
|
}
|
|
}
|
|
}
|