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

Function TestImportCommand_DuplicateSkip

apps/cli/internal/cli/importcmd_test.go:164–229  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

162}
163
164func TestImportCommand_DuplicateSkip(t *testing.T) {
165 sourceName := "test-import-cli-dedup"
166 defer sync.Unregister(sourceName)
167
168 sync.Register(&cliMockSource{
169 name: sourceName,
170 tasks: []sync.ExternalTask{
171 {ExternalID: "DUP-1", Title: "Already exists", Status: "open"},
172 {ExternalID: "NEW-1", Title: "Brand new", Status: "open"},
173 },
174 })
175
176 tmpDir := t.TempDir()
177 origDir, _ := os.Getwd()
178 if err := os.Chdir(tmpDir); err != nil {
179 t.Fatal(err)
180 }
181 defer os.Chdir(origDir)
182
183 // Create an existing task with external_id DUP-1
184 tasksDir := filepath.Join(tmpDir, "tasks")
185 if err := os.MkdirAll(tasksDir, 0755); err != nil {
186 t.Fatal(err)
187 }
188 existingContent := "---\nid: \"001\"\ntitle: \"Existing\"\nstatus: pending\nexternal_id: \"DUP-1\"\n---\n"
189 if err := os.WriteFile(filepath.Join(tasksDir, "001-existing.md"), []byte(existingContent), 0644); err != nil {
190 t.Fatal(err)
191 }
192
193 resetImportFlags()
194 importSource = sourceName
195 importOutDir = tasksDir
196 importFormat = "json"
197
198 // Capture stdout
199 old := os.Stdout
200 r, w, _ := os.Pipe()
201 os.Stdout = w
202
203 err := runImport(importCmd, nil)
204
205 w.Close()
206 os.Stdout = old
207
208 if err != nil {
209 t.Fatalf("unexpected error: %v", err)
210 }
211
212 var buf bytes.Buffer
213 buf.ReadFrom(r)
214
215 var data importResultData
216 if err := json.Unmarshal(buf.Bytes(), &data); err != nil {
217 t.Fatalf("invalid JSON: %v", err)
218 }
219
220 if data.Summary.Created != 1 {
221 t.Errorf("expected 1 created, got %d", data.Summary.Created)

Callers

nothing calls this directly

Calls 2

resetImportFlagsFunction · 0.85
runImportFunction · 0.85

Tested by

no test coverage detected