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

Function TestImportCommand_JSONOutput

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

Source from the content-addressed store, hash-verified

104}
105
106func TestImportCommand_JSONOutput(t *testing.T) {
107 sourceName := "test-import-cli-json"
108 defer sync.Unregister(sourceName)
109
110 sync.Register(&cliMockSource{
111 name: sourceName,
112 tasks: []sync.ExternalTask{
113 {ExternalID: "JSON-1", Title: "JSON output task", Status: "open"},
114 },
115 })
116
117 tmpDir := t.TempDir()
118 origDir, _ := os.Getwd()
119 if err := os.Chdir(tmpDir); err != nil {
120 t.Fatal(err)
121 }
122 defer os.Chdir(origDir)
123
124 resetImportFlags()
125 importSource = sourceName
126 importOutDir = filepath.Join(tmpDir, "tasks")
127 importFormat = "json"
128
129 // Capture stdout
130 old := os.Stdout
131 r, w, _ := os.Pipe()
132 os.Stdout = w
133
134 err := runImport(importCmd, nil)
135
136 w.Close()
137 os.Stdout = old
138
139 if err != nil {
140 t.Fatalf("unexpected error: %v", err)
141 }
142
143 var buf bytes.Buffer
144 buf.ReadFrom(r)
145 output := buf.String()
146
147 // Verify valid JSON
148 var data importResultData
149 if err := json.Unmarshal([]byte(output), &data); err != nil {
150 t.Fatalf("invalid JSON output: %v\nOutput:\n%s", err, output)
151 }
152
153 if data.Summary.Created != 1 {
154 t.Errorf("expected 1 created in summary, got %d", data.Summary.Created)
155 }
156 if len(data.Created) != 1 {
157 t.Errorf("expected 1 created item, got %d", len(data.Created))
158 }
159 if data.Created[0].ExternalID != "JSON-1" {
160 t.Errorf("expected external_id JSON-1, got %s", data.Created[0].ExternalID)
161 }
162}
163

Callers

nothing calls this directly

Calls 2

resetImportFlagsFunction · 0.85
runImportFunction · 0.85

Tested by

no test coverage detected