MCPcopy Create free account
hub / github.com/driangle/taskmd / TestWarnDuplicateIDs

Function TestWarnDuplicateIDs

apps/cli/internal/cli/duplicate_test.go:81–143  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

79}
80
81func TestWarnDuplicateIDs(t *testing.T) {
82 t.Run("prints warning for duplicates", func(t *testing.T) {
83 tasks := []*model.Task{
84 {ID: "042", FilePath: "tasks/cli/042-foo.md"},
85 {ID: "042", FilePath: "tasks/web/042-bar.md"},
86 {ID: "001", FilePath: "tasks/001.md"},
87 }
88
89 oldStderr := os.Stderr
90 r, w, _ := os.Pipe()
91 os.Stderr = w
92
93 dupes := warnDuplicateIDs(tasks)
94
95 w.Close()
96 os.Stderr = oldStderr
97
98 var buf bytes.Buffer
99 buf.ReadFrom(r)
100 output := buf.String()
101
102 if len(dupes) != 1 {
103 t.Fatalf("expected 1 duplicate ID, got %d", len(dupes))
104 }
105
106 if !strings.Contains(output, `ID "042"`) {
107 t.Errorf("expected warning to mention ID 042, got: %s", output)
108 }
109 if !strings.Contains(output, "tasks/cli/042-foo.md") {
110 t.Errorf("expected warning to mention file path, got: %s", output)
111 }
112 if !strings.Contains(output, "taskmd deduplicate") {
113 t.Errorf("expected warning to mention deduplicate command, got: %s", output)
114 }
115 })
116
117 t.Run("no output when no duplicates", func(t *testing.T) {
118 tasks := []*model.Task{
119 {ID: "001", FilePath: "a/001.md"},
120 {ID: "002", FilePath: "a/002.md"},
121 }
122
123 oldStderr := os.Stderr
124 r, w, _ := os.Pipe()
125 os.Stderr = w
126
127 dupes := warnDuplicateIDs(tasks)
128
129 w.Close()
130 os.Stderr = oldStderr
131
132 var buf bytes.Buffer
133 buf.ReadFrom(r)
134 output := buf.String()
135
136 if len(dupes) != 0 {
137 t.Fatalf("expected no duplicates, got %d", len(dupes))
138 }

Callers

nothing calls this directly

Calls 1

warnDuplicateIDsFunction · 0.85

Tested by

no test coverage detected