From 8ebaeefba1ae3e8ecbb84a1a15255639d9d65bf7 Mon Sep 17 00:00:00 2001 From: Dmitrii Gridnev Date: Mon, 16 Sep 2024 10:33:04 +0200 Subject: [PATCH] feature: improve handling suites and outputs 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. --- internal/parsers/junit/junit.go | 41 ++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/internal/parsers/junit/junit.go b/internal/parsers/junit/junit.go index 41fa746..e8e39e2 100644 --- a/internal/parsers/junit/junit.go +++ b/internal/parsers/junit/junit.go @@ -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 @@ -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" @@ -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) } }