summaryrefslogtreecommitdiff
path: root/internal/task/task_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-25 18:18:59 +0300
committerPaul Buetow <paul@buetow.org>2026-06-25 18:18:59 +0300
commitbca7d87f11a3ee88c75dc1ed706009d63022ef98 (patch)
tree70b5bed95f11bc30968917d8c088fa8b7697cfac /internal/task/task_test.go
parentb642f71049ba6030e45c9ddead6d1cc2b7e289e2 (diff)
fr0 add recurring series recurrence edit
Diffstat (limited to 'internal/task/task_test.go')
-rw-r--r--internal/task/task_test.go95
1 files changed, 95 insertions, 0 deletions
diff --git a/internal/task/task_test.go b/internal/task/task_test.go
index 570cc86..acd0978 100644
--- a/internal/task/task_test.go
+++ b/internal/task/task_test.go
@@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
+ "reflect"
"strings"
"testing"
"time"
@@ -824,6 +825,100 @@ func TestRecurringSeries(t *testing.T) {
}
}
+func TestSetRecurringSeriesRecurrenceContext(t *testing.T) {
+ tmp := t.TempDir()
+ taskPath := filepath.Join(tmp, "task")
+ logFile := filepath.Join(tmp, "commands.txt")
+
+ script := fmt.Sprintf(`#!/bin/sh
+if [ "$1" = "(root or parent:root)" ] && [ "$2" = "status.any:" ] && [ "$3" = "export" ]; then
+ echo '{"id":0,"uuid":"root","description":"template","status":"recurring","recur":"daily"}'
+ echo '{"id":1,"uuid":"child-1","parent":"root","description":"child 1","status":"pending","recur":"daily"}'
+ echo '{"id":2,"uuid":"child-2","parent":"root","description":"child 2","status":"pending","recur":"daily"}'
+ exit 0
+fi
+echo "$@" >> %s
+`, shellQuote(logFile))
+ if err := os.WriteFile(taskPath, []byte(script), 0o755); err != nil {
+ t.Fatal(err)
+ }
+
+ origPath := os.Getenv("PATH")
+ if err := os.Setenv("PATH", tmp+":"+origPath); err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() {
+ if err := os.Setenv("PATH", origPath); err != nil {
+ t.Errorf("restore PATH: %v", err)
+ }
+ })
+
+ if err := SetRecurringSeriesRecurrenceContext(context.Background(), "root", "weekly"); err != nil {
+ t.Fatalf("SetRecurringSeriesRecurrenceContext: %v", err)
+ }
+
+ got := readLinesFile(t, logFile)
+ want := []string{
+ "rc.recurrence.confirmation=no child-1 modify recur:weekly",
+ "rc.recurrence.confirmation=no child-2 modify recur:weekly",
+ "rc.recurrence.confirmation=no root modify recur:weekly",
+ }
+ if !reflect.DeepEqual(got, want) {
+ t.Fatalf("commands:\ngot %#v\nwant %#v", got, want)
+ }
+}
+
+func TestSetRecurringSeriesRecurrenceContextRollsBackCompletedUpdates(t *testing.T) {
+ tmp := t.TempDir()
+ taskPath := filepath.Join(tmp, "task")
+ logFile := filepath.Join(tmp, "commands.txt")
+
+ script := fmt.Sprintf(`#!/bin/sh
+if [ "$1" = "(root or parent:root)" ] && [ "$2" = "status.any:" ] && [ "$3" = "export" ]; then
+ echo '{"id":0,"uuid":"root","description":"template","status":"recurring","recur":"daily"}'
+ echo '{"id":1,"uuid":"child-1","parent":"root","description":"child 1","status":"pending","recur":"daily"}'
+ echo '{"id":2,"uuid":"child-2","parent":"root","description":"child 2","status":"pending","recur":"monthly"}'
+ exit 0
+fi
+echo "$@" >> %s
+if [ "$2" = "child-2" ] && [ "$4" = "recur:weekly" ]; then
+ echo "child-2 failed" >&2
+ exit 1
+fi
+`, shellQuote(logFile))
+ if err := os.WriteFile(taskPath, []byte(script), 0o755); err != nil {
+ t.Fatal(err)
+ }
+
+ origPath := os.Getenv("PATH")
+ if err := os.Setenv("PATH", tmp+":"+origPath); err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() {
+ if err := os.Setenv("PATH", origPath); err != nil {
+ t.Errorf("restore PATH: %v", err)
+ }
+ })
+
+ err := SetRecurringSeriesRecurrenceContext(context.Background(), "root", "weekly")
+ if err == nil {
+ t.Fatal("expected SetRecurringSeriesRecurrenceContext error")
+ }
+ if !strings.Contains(err.Error(), "set recurrence for child-2") {
+ t.Fatalf("error = %v, want child-2 context", err)
+ }
+
+ got := readLinesFile(t, logFile)
+ want := []string{
+ "rc.recurrence.confirmation=no child-1 modify recur:weekly",
+ "rc.recurrence.confirmation=no child-2 modify recur:weekly",
+ "rc.recurrence.confirmation=no child-1 modify recur:daily",
+ }
+ if !reflect.DeepEqual(got, want) {
+ t.Fatalf("commands:\ngot %#v\nwant %#v", got, want)
+ }
+}
+
func TestModifyHelpers(t *testing.T) {
if _, err := exec.LookPath("task"); err != nil {
t.Skip("task command not available")