TestStatusCommand_JSONOutputValidation tests that the status command with --json flag returns valid JSON
(t *testing.T)
| 102 | |
| 103 | // TestStatusCommand_JSONOutputValidation tests that the status command with --json flag returns valid JSON |
| 104 | func TestStatusCommand_JSONOutputValidation(t *testing.T) { |
| 105 | // Skip if the binary doesn't exist |
| 106 | binaryPath := "../../gh-aw" |
| 107 | if _, err := os.Stat(binaryPath); os.IsNotExist(err) { |
| 108 | t.Skip("Skipping test: gh-aw binary not found. Run 'make build' first.") |
| 109 | } |
| 110 | |
| 111 | // Get the current directory for proper path resolution |
| 112 | originalDir, err := os.Getwd() |
| 113 | if err != nil { |
| 114 | t.Fatalf("Failed to get current directory: %v", err) |
| 115 | } |
| 116 | |
| 117 | // Change to repository root |
| 118 | repoRoot := filepath.Join(originalDir, "..", "..") |
| 119 | if err := os.Chdir(repoRoot); err != nil { |
| 120 | t.Fatalf("Failed to change to repository root: %v", err) |
| 121 | } |
| 122 | defer os.Chdir(originalDir) |
| 123 | |
| 124 | // Run the status command with --json flag |
| 125 | cmd := exec.Command(filepath.Join(originalDir, binaryPath), "status", "--json") |
| 126 | var stdout, stderr bytes.Buffer |
| 127 | cmd.Stdout = &stdout |
| 128 | cmd.Stderr = &stderr |
| 129 | |
| 130 | err = cmd.Run() |
| 131 | if err != nil { |
| 132 | t.Logf("Command stderr: %s", stderr.String()) |
| 133 | t.Fatalf("Failed to run status command: %v", err) |
| 134 | } |
| 135 | |
| 136 | // Verify the output is valid JSON |
| 137 | output := stdout.String() |
| 138 | if output == "" { |
| 139 | t.Fatal("Expected non-empty JSON output") |
| 140 | } |
| 141 | |
| 142 | // Try to parse as JSON array |
| 143 | var statuses []WorkflowStatus |
| 144 | if err := json.Unmarshal([]byte(output), &statuses); err != nil { |
| 145 | t.Fatalf("Output is not valid JSON: %v\nOutput: %s", err, output) |
| 146 | } |
| 147 | |
| 148 | // Verify we got an array (even if empty) |
| 149 | if statuses == nil { |
| 150 | t.Error("Expected JSON array, got nil") |
| 151 | } |
| 152 | |
| 153 | // If we have workflows, verify structure |
| 154 | if len(statuses) > 0 { |
| 155 | firstStatus := statuses[0] |
| 156 | |
| 157 | // Verify all required fields are present |
| 158 | if firstStatus.Workflow == "" { |
| 159 | t.Error("Expected 'workflow' field to be non-empty") |
| 160 | } |
| 161 | if firstStatus.EngineID == "" { |