Repository navigation
Expand file tree
/
Copy pathstacking_example_test.go
More file actions
111 lines (89 loc) · 4.2 KB
/
Copy pathstacking_example_test.go
File metadata and controls
111 lines (89 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package dispatch_test
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/kapetan-io/dispatch"
)
const importStacking = `import "./stacking";`
func TestTheStackingExampleLaunchesATicketOnItsBlockersReadyPR(t *testing.T) {
t.Parallel()
d := newDispatch(t, dispatchOptions{Env: launchEnv, Launcher: builtinLauncher, Rules: shippedRulesAnd(t, importStacking+reportRule)})
head := stackedPair(t, d)
d.Workers.Running("ENG-1", "idle")
d.GitHub.PullRequest("ENG-1", prState{head: head, checks: "SUCCESS", mergeable: "MERGEABLE"})
d.Tick()
assert.Equal(t, []string{"w2:p2|/dispatch:build ENG-2 --base thrawn01/eng-1"}, d.fakes().Multiplexer.Kicked())
assert.Equal(t, "stack ENG-1@"+head+" branch thrawn01/eng-2", lastReadingOf(d, "ENG-2"))
}
func TestTheStackingExampleLeavesABlockerWithoutAReadyPRWaiting(t *testing.T) {
t.Parallel()
d := newDispatch(t, dispatchOptions{Env: launchEnv, Launcher: builtinLauncher, Rules: shippedRulesAnd(t, importStacking+reportRule)})
head := stackedPair(t, d)
d.Workers.Running("ENG-1", "idle")
d.GitHub.PullRequest("ENG-1", prState{head: head, checks: "FAILURE", mergeable: "MERGEABLE"})
d.Tick()
assert.Empty(t, d.fakes().Multiplexer.Kicked())
// The shipped rules also comment that ENG-2 is blocked, in either order.
assert.Contains(t, d.Linear.Comments(), "ENG-2: stack none branch thrawn01/eng-2")
}
func TestTheStackingExampleRelaunchesATicketThatOwesARestackWithOneLaunch(t *testing.T) {
t.Parallel()
d := newDispatch(t, dispatchOptions{Env: launchEnv, Launcher: builtinLauncher, Rules: shippedRulesAnd(t, importStacking+reportRule)})
d.Trees.Pooled()
const fork = "0123456789abcdef0123456789abcdef01234567"
hintGit(t, d.Repo, "branch", "thrawn01/eng-2", "main")
hintGit(t, d.Repo, "config", "branch.thrawn01/eng-2.dispatchStackParent", "ENG-1")
hintGit(t, d.Repo, "config", "branch.thrawn01/eng-2.dispatchStackForkPoint", fork)
// ENG-1 is Done, so ENG-2 has no open blocker and launch-worker would start a plain build.
d.Linear.Tickets(ticket("ENG-2", "In Progress", "dispatch"))
d.Tick()
require.Len(t, d.receiptsOfKind("ENG-2", "launch"), 1)
kicked := d.fakes().Multiplexer.Kicked()
require.Len(t, kicked, 1)
assert.Contains(t, kicked[0], "git rebase --onto origin/<default> "+fork)
assert.Contains(t, kicked[0], "ticket branch ENG-2 --unstack")
assert.Equal(t, "stack ENG-1@"+fork+" branch thrawn01/eng-2", lastReadingOf(d, "ENG-2"))
assert.Empty(t, dispatchKeys(t, d.Repo))
}
func TestRulesTestAcceptsSeveralEntryFilesInRulesFrom(t *testing.T) {
t.Parallel()
d := newDispatch(t, dispatchOptions{})
dir := filepath.Join(t.TempDir(), "rules")
require.NoError(t, d.Run("rules", "init", dir).Err)
tests, err := filepath.Glob(filepath.Join(dir, "*.test.ts"))
require.NoError(t, err)
for _, path := range tests {
require.NoError(t, os.Remove(path))
}
require.NoError(t, os.WriteFile(filepath.Join(dir, "both.test.ts"), []byte(`
import { scenario, ticket, worker, pr, rulesFrom } from "dispatch/testing";
const rules = rulesFrom("./dispatch", "./stacking");
scenario(rules, "the entries load together", s => {
s.given(ticket("ENG-1", { status: "in_review", optedIn: true, repo: "dispatch" }), worker("ENG-1", "idle"), pr("ENG-1", { problems: ["a failed check"] }));
s.expect([["nudge-pr-needs-work", "nudge", "ENG-1"]]);
});
`), 0o644))
res := d.RunWith(dispatch.Options{RulesDir: dir}, "rules", "test")
require.NoError(t, res.Err)
assert.Contains(t, res.Stdout, "1 scenarios, 1 passed, 0 failed")
}
func TestRulesTestReportsAnEntryFileThatDoesNotExist(t *testing.T) {
t.Parallel()
d := newDispatch(t, dispatchOptions{})
dir := filepath.Join(t.TempDir(), "rules")
require.NoError(t, d.Run("rules", "init", dir).Err)
tests, err := filepath.Glob(filepath.Join(dir, "*.test.ts"))
require.NoError(t, err)
for _, path := range tests {
require.NoError(t, os.Remove(path))
}
require.NoError(t, os.WriteFile(filepath.Join(dir, "missing.test.ts"), []byte(`
import { scenario, rulesFrom } from "dispatch/testing";
scenario(rulesFrom("./dispatch", "./nothing"), "never runs", s => {});
`), 0o644))
res := d.RunWith(dispatch.Options{RulesDir: dir}, "rules", "test")
require.ErrorContains(t, res.Err, "nothing")
}