(t *testing.T)
| 1011 | } |
| 1012 | |
| 1013 | func TestCmdListProjectsFormatJSON(t *testing.T) { |
| 1014 | root, db := showListEditDB(t) |
| 1015 | insertProject(t, db, "p1", "P1", filepath.Join(root, "x"), "high") |
| 1016 | insertTask(t, db, "p1-ip", "I", "in-progress", "high", filepath.Join(root, "x"), "p1") |
| 1017 | insertTask(t, db, "p1-bl", "B", "backlog", "medium", filepath.Join(root, "x"), "p1") |
| 1018 | |
| 1019 | out := captureStdout(t, func() { |
| 1020 | if rc := cmdList([]string{"projects", "--format", "json"}); rc != 0 { |
| 1021 | t.Fatalf("rc=%d", rc) |
| 1022 | } |
| 1023 | }) |
| 1024 | var rows []map[string]any |
| 1025 | if err := json.Unmarshal([]byte(out), &rows); err != nil { |
| 1026 | t.Fatalf("invalid JSON: %v\nout=%q", err, out) |
| 1027 | } |
| 1028 | if len(rows) != 1 { |
| 1029 | t.Fatalf("want 1 project, got %d", len(rows)) |
| 1030 | } |
| 1031 | r := rows[0] |
| 1032 | if r["slug"] != "p1" { |
| 1033 | t.Errorf("slug = %v, want p1", r["slug"]) |
| 1034 | } |
| 1035 | if r["in_progress"].(float64) != 1 || r["backlog"].(float64) != 1 { |
| 1036 | t.Errorf("breakdown wrong: %+v", r) |
| 1037 | } |
| 1038 | // `name` is included in JSON so the workspace layer gets legible titles. |
| 1039 | if r["name"] != "P1" { |
| 1040 | t.Errorf("name = %v, want P1", r["name"]) |
| 1041 | } |
| 1042 | } |
nothing calls this directly
no test coverage detected