aboutsummaryrefslogtreecommitdiffstats
path: root/lib/pama/drop_test.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2024-01-31 16:49:28 +0100
committerRobin Jarry <robin@jarry.cc>2024-01-31 16:54:31 +0100
commitb285b894c3de7299452e860fc060b673af279261 (patch)
treed3f834db15ffe749708d734c0b6cd0645de7aabf /lib/pama/drop_test.go
parentf16b33f752bbc3086d08ba8fde034de48ab1c6d6 (diff)
downloadaerc-b285b894c3de7299452e860fc060b673af279261.tar.gz
commands: rename patch remove to patch drop
Rename the :patch remove command to :patch drop to better express the this operation is the counter-part to :patch apply. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/pama/drop_test.go')
-rw-r--r--lib/pama/drop_test.go85
1 files changed, 85 insertions, 0 deletions
diff --git a/lib/pama/drop_test.go b/lib/pama/drop_test.go
new file mode 100644
index 00000000..84bc2864
--- /dev/null
+++ b/lib/pama/drop_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_Drop(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
+ drop string
+ commits []models.Commit
+ want []models.Commit
+ }{
+ {
+ name: "drop only patch",
+ drop: "patch1",
+ commits: []models.Commit{
+ newCommit("1", "a", "patch1"),
+ },
+ want: []models.Commit{},
+ },
+ {
+ name: "drop second one of two patch",
+ drop: "patch2",
+ commits: []models.Commit{
+ newCommit("1", "a", "patch1"),
+ newCommit("2", "b", "patch2"),
+ },
+ want: []models.Commit{
+ newCommit("1", "a", "patch1"),
+ },
+ },
+ {
+ name: "drop first one of two patch",
+ drop: "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.DropPatch(test.drop)
+ 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)
+ }
+ }
+ }
+}