gunk-dev/the-valley

rebase_test.go

sourced776ee7feecfmain's published tip history
2.8 KiB
1package main
2
3import "testing"
4
5// The manifest lines up the layers' names, says for each change whether a
6// version was added, and gives the command that finishes each change whose
7// branch may hold its rebased head with no version recording it: one
8// pushed and left without a version, or one whose push may have reached
9// origin. A plain branch is never unfinished, and neither is a change
10// whose branch did not move.
11func TestManifest(t *testing.T) {
12 const (
13 o1, n1 = "1111111aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "1111111bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
14 o2, n2 = "2222222aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "2222222bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
15 o3, n3 = "3333333aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "3333333bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
16 id2 = "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"
17 id3 = "pppppppppppppppppppppppppppppppp"
18 )
19 stack := func(pushed string, added2, added3 int) []*layer {
20 return []*layer{
21 {name: "topic/one", branch: "topic/one", head: o1, rebased: n1, pushed: pushed},
22 {name: "qqqq", id: id2, branch: "two", head: o2, rebased: n2, pushed: pushed, added: added2},
23 {name: "pppp", id: id3, branch: "my branch", head: o3, rebased: n3, pushed: pushed, added: added3},
24 }
25 }
26 for _, c := range []struct {
27 name string
28 layers []*layer
29 want string
30 }{
31 {"finished", stack(pushDone, 2, 4), `the stack under pppp, bottom first:
32 topic/one 1111111 -> 1111111 origin/topic/one pushed
33 qqqq 2222222 -> 2222222 origin/two pushed, v2 added
34 pppp 3333333 -> 3333333 origin/my branch pushed, v4 added
35`},
36 {"one change left without a version", stack(pushDone, 0, 4), `the stack under pppp, bottom first:
37 topic/one 1111111 -> 1111111 origin/topic/one pushed
38 qqqq 2222222 -> 2222222 origin/two pushed, no version added
39 pppp 3333333 -> 3333333 origin/my branch pushed, v4 added
40to finish qqqq: valley ready --head ` + n2 + ` --change ` + id2 + ` two
41`},
42 {"refused", stack(pushNot, 0, 0), `the stack under pppp, bottom first:
43 topic/one 1111111 -> 1111111 origin/topic/one not pushed
44 qqqq 2222222 -> 2222222 origin/two not pushed, no version added
45 pppp 3333333 -> 3333333 origin/my branch not pushed, no version added
46`},
47 {"not known", stack(pushUnknown, 0, 0), `the stack under pppp, bottom first:
48 topic/one 1111111 -> 1111111 origin/topic/one may have moved
49 qqqq 2222222 -> 2222222 origin/two may have moved, no version added
50 pppp 3333333 -> 3333333 origin/my branch may have moved, no version added
51to finish qqqq: valley ready --head ` + n2 + ` --change ` + id2 + ` two
52to finish pppp: valley ready --head ` + n3 + ` --change ` + id3 + ` my\ branch
53`},
54 } {
55 if got := manifest("pppp", c.layers); got != c.want {
56 t.Errorf("%s:\n%s\nwant:\n%s", c.name, got, c.want)
57 }
58 }
59}