(t *testing.T)
| 104 | } |
| 105 | |
| 106 | func TestGraphCommand_JSON_Format(t *testing.T) { |
| 107 | tmpDir := createTestTaskFiles(t) |
| 108 | |
| 109 | // Reset flags |
| 110 | graphFormat = "json" |
| 111 | graphExcludeStatus = []string{} |
| 112 | graphAll = false |
| 113 | graphRoot = "" |
| 114 | graphFocus = "" |
| 115 | graphUpstream = false |
| 116 | graphDownstream = false |
| 117 | graphOut = "" |
| 118 | |
| 119 | // Capture stdout |
| 120 | oldStdout := os.Stdout |
| 121 | r, w, _ := os.Pipe() |
| 122 | os.Stdout = w |
| 123 | |
| 124 | // Run command |
| 125 | err := runGraph(graphCmd, []string{tmpDir}) |
| 126 | if err != nil { |
| 127 | t.Fatalf("runGraph failed: %v", err) |
| 128 | } |
| 129 | |
| 130 | // Restore stdout |
| 131 | w.Close() |
| 132 | os.Stdout = oldStdout |
| 133 | |
| 134 | // Read output |
| 135 | var buf bytes.Buffer |
| 136 | buf.ReadFrom(r) |
| 137 | output := buf.String() |
| 138 | |
| 139 | // Parse JSON |
| 140 | var result map[string]any |
| 141 | err = json.Unmarshal([]byte(output), &result) |
| 142 | if err != nil { |
| 143 | t.Fatalf("Failed to parse JSON output: %v", err) |
| 144 | } |
| 145 | |
| 146 | // Verify nodes |
| 147 | nodes, ok := result["nodes"].([]any) |
| 148 | if !ok { |
| 149 | t.Fatal("Expected 'nodes' to be an array") |
| 150 | } |
| 151 | |
| 152 | if len(nodes) != 5 { |
| 153 | t.Errorf("Expected 5 nodes, got %d", len(nodes)) |
| 154 | } |
| 155 | |
| 156 | // Verify edges |
| 157 | edges, ok := result["edges"].([]any) |
| 158 | if !ok { |
| 159 | t.Fatal("Expected 'edges' to be an array") |
| 160 | } |
| 161 | |
| 162 | if len(edges) != 4 { |
| 163 | t.Errorf("Expected 4 edges, got %d", len(edges)) |
nothing calls this directly
no test coverage detected