Debian Codegraph @

lib/pama/drop_test.go

raw
1 package pama_test
2
3 import (
4 "reflect"
5 "testing"
6
7 "git.sr.ht/~rjarry/aerc/lib/pama"
8 "git.sr.ht/~rjarry/aerc/lib/pama/models"
9 )
10
11 func TestPatchmgmt_Drop(t *testing.T) {
12 setup := func(p models.Project) (pama.PatchManager, models.RevisionController, models.PersistentStorer) {
13 return newTestManager(
14 []string{"0", "1", "2", "3", "4", "5"},
15 []string{"0", "a", "b", "c", "d", "f"},
16 map[string]models.Project{p.Name: p}, p.Name,
17 )
18 }
19
20 tests := []struct {
21 name string
22 drop string
23 commits []models.Commit
24 want []models.Commit
25 }{
26 {
27 name: "drop only patch",
28 drop: "patch1",
29 commits: []models.Commit{
30 newCommit("1", "a", "patch1"),
31 },
32 want: []models.Commit{},
33 },
34 {
35 name: "drop second one of two patch",
36 drop: "patch2",
37 commits: []models.Commit{
38 newCommit("1", "a", "patch1"),
39 newCommit("2", "b", "patch2"),
40 },
41 want: []models.Commit{
42 newCommit("1", "a", "patch1"),
43 },
44 },
45 {
46 name: "drop first one of two patch",
47 drop: "patch1",
48 commits: []models.Commit{
49 newCommit("1", "a", "patch1"),
50 newCommit("2", "b", "patch2"),
51 },
52 want: []models.Commit{
53 newCommit("2_new", "b", "patch2"),
54 },
55 },
56 }
57
58 for _, test := range tests {
59 p := models.Project{
60 Name: "project1",
61 Commits: test.commits,
62 Base: newCommit("0", "0", ""),
63 }
64 mgr, rc, _ := setup(p)
65
66 err := mgr.DropPatch(test.drop)
67 if err != nil {
68 t.Errorf("test '%s' failed. %v", test.name, err)
69 }
70
71 q, _ := mgr.CurrentProject()
72 if !reflect.DeepEqual(q.Commits, test.want) {
73 t.Errorf("test '%s' failed. Commits don't match: "+
74 "got %v, but wanted %v", test.name, q.Commits,
75 test.want)
76 }
77
78 if len(test.want) > 0 {
79 last := test.want[len(test.want)-1]
80 if !rc.Exists(last.ID) {
81 t.Errorf("test '%s' failed. Could not find last commits: %v", test.name, last)
82 }
83 }
84 }
85 }