TestStatusCommand_JSONOutputIncludesOnField tests that the "on" field is included in JSON output
(t *testing.T)
| 234 | |
| 235 | // TestStatusCommand_JSONOutputIncludesOnField tests that the "on" field is included in JSON output |
| 236 | func TestStatusCommand_JSONOutputIncludesOnField(t *testing.T) { |
| 237 | // Skip if the binary doesn't exist |
| 238 | binaryPath := "../../gh-aw" |
| 239 | if _, err := os.Stat(binaryPath); os.IsNotExist(err) { |
| 240 | t.Skip("Skipping test: gh-aw binary not found. Run 'make build' first.") |
| 241 | } |
| 242 | |
| 243 | // Get the current directory for proper path resolution |
| 244 | originalDir, err := os.Getwd() |
| 245 | if err != nil { |
| 246 | t.Fatalf("Failed to get current directory: %v", err) |
| 247 | } |
| 248 | |
| 249 | // Change to repository root |
| 250 | repoRoot := filepath.Join(originalDir, "..", "..") |
| 251 | if err := os.Chdir(repoRoot); err != nil { |
| 252 | t.Fatalf("Failed to change to repository root: %v", err) |
| 253 | } |
| 254 | defer os.Chdir(originalDir) |
| 255 | |
| 256 | // Run the status command with --json flag |
| 257 | cmd := exec.Command(filepath.Join(originalDir, binaryPath), "status", "--json") |
| 258 | var stdout, stderr bytes.Buffer |
| 259 | cmd.Stdout = &stdout |
| 260 | cmd.Stderr = &stderr |
| 261 | |
| 262 | err = cmd.Run() |
| 263 | if err != nil { |
| 264 | t.Logf("Command stderr: %s", stderr.String()) |
| 265 | t.Fatalf("Failed to run status command: %v", err) |
| 266 | } |
| 267 | |
| 268 | // Verify the output is valid JSON |
| 269 | output := stdout.String() |
| 270 | if output == "" { |
| 271 | t.Fatal("Expected non-empty JSON output") |
| 272 | } |
| 273 | |
| 274 | // Try to parse as JSON array |
| 275 | var statuses []WorkflowStatus |
| 276 | if err := json.Unmarshal([]byte(output), &statuses); err != nil { |
| 277 | t.Fatalf("Output is not valid JSON: %v\nOutput: %s", err, output) |
| 278 | } |
| 279 | |
| 280 | // If we have workflows, verify "on" field is present |
| 281 | if len(statuses) > 0 { |
| 282 | firstStatus := statuses[0] |
| 283 | |
| 284 | // Verify "on" field is present |
| 285 | if firstStatus.On == nil { |
| 286 | t.Error("Expected 'on' field to be present") |
| 287 | } else { |
| 288 | t.Logf("'on' field for workflow '%s': %v", firstStatus.Workflow, firstStatus.On) |
| 289 | } |
| 290 | |
| 291 | t.Logf("Successfully verified 'on' field for %d workflow(s)", len(statuses)) |
| 292 | } else { |
| 293 | t.Skip("No workflows found to test 'on' field") |