Skip to content

Commit

Permalink
feature: improve handling suites and outputs
Browse files Browse the repository at this point in the history
If we can split a suite by slashes, it will be displayed as a hierarchy.

If the result has console outputs attached, we will add them as attachments.
  • Loading branch information
gibiw committed Sep 16, 2024
1 parent 520c65c commit 4978532
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions internal/parsers/junit/junit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package junit
import (
"encoding/xml"
"fmt"
"github.com/google/uuid"
models "github.com/qase-tms/qasectl/internal/models/result"
"io"
"log"
"log/slog"
"os"
"path/filepath"
"strings"
)

// Parser is a parser for Junit XML files
Expand Down Expand Up @@ -109,13 +111,23 @@ func convertTestSuites(testSuites TestSuites) []models.Result {
{
Title: testSuites.Name,
},
{
Title: testSuite.Name,
},
},
},
}

parts := strings.Split(testSuite.Name, string(filepath.Separator))
if len(parts) > 1 {
for _, part := range parts {
relation.Suite.Data = append(relation.Suite.Data, models.SuiteData{
Title: part,
})
}
} else {
relation.Suite.Data = append(relation.Suite.Data, models.SuiteData{
Title: testSuite.Name,
})
}

signature := fmt.Sprintf("%s::%s::%s::%s", testSuites.Name, testSuite.Name, testCase.ClassName, testCase.Name)

status := "passed"
Expand Down Expand Up @@ -162,6 +174,29 @@ func convertTestSuites(testSuites TestSuites) []models.Result {
Fields: fields,
Message: message,
}

if testCase.SystemOut != "" {
c := []byte(testCase.SystemOut)
id := uuid.New()
result.Attachments = append(result.Attachments, models.Attachment{
ID: &id,
Name: "system-out.txt",
ContentType: "plain/text",
Content: &c,
})
}

if testCase.SystemErr != "" {
c := []byte(testCase.SystemErr)
id := uuid.New()
result.Attachments = append(result.Attachments, models.Attachment{
ID: &id,
Name: "system-err.txt",
ContentType: "plain/text",
Content: &c,
})
}

results = append(results, result)
}
}
Expand Down

0 comments on commit 4978532

Please sign in to comment.