(t *testing.T)
| 159 | } |
| 160 | |
| 161 | func TestBuildJUnitSuites_ValidXML(t *testing.T) { |
| 162 | reports := map[string]*models.TestReport{ |
| 163 | "test-set-1": { |
| 164 | Total: 1, |
| 165 | Success: 1, |
| 166 | TimeTaken: "100ms", |
| 167 | Tests: []models.TestResult{ |
| 168 | { |
| 169 | TestCaseID: "tc-1", |
| 170 | Name: "test-set-1", |
| 171 | Status: models.TestStatusPassed, |
| 172 | TimeTaken: "100ms", |
| 173 | }, |
| 174 | }, |
| 175 | }, |
| 176 | } |
| 177 | |
| 178 | suites := buildJUnitSuites(reports) |
| 179 | data, err := xml.MarshalIndent(suites, "", " ") |
| 180 | if err != nil { |
| 181 | t.Fatalf("failed to marshal JUnit XML: %v", err) |
| 182 | } |
| 183 | |
| 184 | xmlStr := xml.Header + string(data) |
| 185 | |
| 186 | if !strings.Contains(xmlStr, `<?xml version="1.0"`) { |
| 187 | t.Error("expected XML declaration") |
| 188 | } |
| 189 | if !strings.Contains(xmlStr, `<testsuites`) { |
| 190 | t.Error("expected <testsuites> root element") |
| 191 | } |
| 192 | if !strings.Contains(xmlStr, `<testsuite`) { |
| 193 | t.Error("expected <testsuite> element") |
| 194 | } |
| 195 | if !strings.Contains(xmlStr, `<testcase`) { |
| 196 | t.Error("expected <testcase> element") |
| 197 | } |
| 198 | |
| 199 | // Verify it's valid XML by unmarshaling back |
| 200 | var parsed junitTestSuites |
| 201 | if err := xml.Unmarshal(data, &parsed); err != nil { |
| 202 | t.Fatalf("generated XML is not valid: %v", err) |
| 203 | } |
| 204 | if parsed.Tests != 1 { |
| 205 | t.Errorf("round-trip: expected 1 test, got %d", parsed.Tests) |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | func TestFmtSeconds(t *testing.T) { |
| 210 | tests := []struct { |
nothing calls this directly
no test coverage detected