TestStatusCommand_JSONOutputWithPattern tests that status --json works with a pattern filter
(t *testing.T)
| 179 | |
| 180 | // TestStatusCommand_JSONOutputWithPattern tests that status --json works with a pattern filter |
| 181 | func TestStatusCommand_JSONOutputWithPattern(t *testing.T) { |
| 182 | // Skip if the binary doesn't exist |
| 183 | binaryPath := "../../gh-aw" |
| 184 | if _, err := os.Stat(binaryPath); os.IsNotExist(err) { |
| 185 | t.Skip("Skipping test: gh-aw binary not found. Run 'make build' first.") |
| 186 | } |
| 187 | |
| 188 | // Get the current directory for proper path resolution |
| 189 | originalDir, err := os.Getwd() |
| 190 | if err != nil { |
| 191 | t.Fatalf("Failed to get current directory: %v", err) |
| 192 | } |
| 193 | |
| 194 | // Change to repository root |
| 195 | repoRoot := filepath.Join(originalDir, "..", "..") |
| 196 | if err := os.Chdir(repoRoot); err != nil { |
| 197 | t.Fatalf("Failed to change to repository root: %v", err) |
| 198 | } |
| 199 | defer os.Chdir(originalDir) |
| 200 | |
| 201 | // Run the status command with --json flag and pattern |
| 202 | cmd := exec.Command(filepath.Join(originalDir, binaryPath), "status", "smoke", "--json") |
| 203 | var stdout, stderr bytes.Buffer |
| 204 | cmd.Stdout = &stdout |
| 205 | cmd.Stderr = &stderr |
| 206 | |
| 207 | err = cmd.Run() |
| 208 | if err != nil { |
| 209 | t.Logf("Command stderr: %s", stderr.String()) |
| 210 | t.Fatalf("Failed to run status command with pattern: %v", err) |
| 211 | } |
| 212 | |
| 213 | // Verify the output is valid JSON |
| 214 | output := stdout.String() |
| 215 | if output == "" { |
| 216 | t.Fatal("Expected non-empty JSON output") |
| 217 | } |
| 218 | |
| 219 | // Try to parse as JSON array |
| 220 | var statuses []WorkflowStatus |
| 221 | if err := json.Unmarshal([]byte(output), &statuses); err != nil { |
| 222 | t.Fatalf("Output is not valid JSON: %v\nOutput: %s", err, output) |
| 223 | } |
| 224 | |
| 225 | // All filtered results should contain "smoke" in the workflow name |
| 226 | for _, status := range statuses { |
| 227 | if !strings.Contains(strings.ToLower(status.Workflow), "smoke") { |
| 228 | t.Errorf("Expected workflow name to contain 'smoke', got: %s", status.Workflow) |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | t.Logf("Successfully parsed %d filtered workflow status entries", len(statuses)) |
| 233 | } |
| 234 | |
| 235 | // TestStatusCommand_JSONOutputIncludesOnField tests that the "on" field is included in JSON output |
| 236 | func TestStatusCommand_JSONOutputIncludesOnField(t *testing.T) { |