diff options
author | Koni Marti <koni.marti@gmail.com> | 2023-11-24 16:03:04 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-12-30 15:42:09 +0100 |
commit | 41e066768c18268fe3deecc60b5797e26f44cf4e (patch) | |
tree | e3e14165ef3a5308d9205bc8f6d4f1831ec654c8 /lib/pama/remove_test.go | |
parent | cf47763e5582563f712b4a40a9b299378aba9003 (diff) | |
download | aerc-41e066768c18268fe3deecc60b5797e26f44cf4e.tar.gz |
patch/remove: add remove sub-cmd
Implement the :patch remove command. Remove a patch set from the
respository and from the internal storage. Note that in git, this will
change all commit hashes that appear after the removed one since the
commit hash depends on its parents. Adjust the code to handle such cases
and add tests for this.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/pama/remove_test.go')
-rw-r--r-- | lib/pama/remove_test.go | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/lib/pama/remove_test.go b/lib/pama/remove_test.go new file mode 100644 index 00000000..c9ce6c65 --- /dev/null +++ b/lib/pama/remove_test.go @@ -0,0 +1,85 @@ +package pama_test + +import ( + "reflect" + "testing" + + "git.sr.ht/~rjarry/aerc/lib/pama" + "git.sr.ht/~rjarry/aerc/lib/pama/models" +) + +func TestPatchmgmt_Remove(t *testing.T) { + setup := func(p models.Project) (pama.PatchManager, models.RevisionController, models.PersistentStorer) { + return newTestManager( + []string{"0", "1", "2", "3", "4", "5"}, + []string{"0", "a", "b", "c", "d", "f"}, + map[string]models.Project{p.Name: p}, p.Name, + ) + } + + tests := []struct { + name string + remove string + commits []models.Commit + want []models.Commit + }{ + { + name: "remove only patch", + remove: "patch1", + commits: []models.Commit{ + newCommit("1", "a", "patch1"), + }, + want: []models.Commit{}, + }, + { + name: "remove second one of two patch", + remove: "patch2", + commits: []models.Commit{ + newCommit("1", "a", "patch1"), + newCommit("2", "b", "patch2"), + }, + want: []models.Commit{ + newCommit("1", "a", "patch1"), + }, + }, + { + name: "remove first one of two patch", + remove: "patch1", + commits: []models.Commit{ + newCommit("1", "a", "patch1"), + newCommit("2", "b", "patch2"), + }, + want: []models.Commit{ + newCommit("2_new", "b", "patch2"), + }, + }, + } + + for _, test := range tests { + p := models.Project{ + Name: "project1", + Commits: test.commits, + Base: newCommit("0", "0", ""), + } + mgr, rc, _ := setup(p) + + err := mgr.RemovePatch(test.remove) + if err != nil { + t.Errorf("test '%s' failed. %v", test.name, err) + } + + q, _ := mgr.CurrentProject() + if !reflect.DeepEqual(q.Commits, test.want) { + t.Errorf("test '%s' failed. Commits don't match: "+ + "got %v, but wanted %v", test.name, q.Commits, + test.want) + } + + if len(test.want) > 0 { + last := test.want[len(test.want)-1] + if !rc.Exists(last.ID) { + t.Errorf("test '%s' failed. Could not find last commits: %v", test.name, last) + } + } + } +} |