Skip to content

Commit

Permalink
fix: an issue with uploading allure results
Browse files Browse the repository at this point in the history
  • Loading branch information
gibiw committed Nov 18, 2024
1 parent 2776978 commit fa7028d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
8 changes: 5 additions & 3 deletions internal/client/converterv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,18 @@ func (c *ClientV2) createStepModel(ctx context.Context, projectCode string, step
m := apiV2Client.NewResultStep()
d := apiV2Client.NewResultStepData(step.Data.Action)
m.SetData(*d)
m.SetExecution(c.createStepExecution(step.Execution))
m.SetExecution(c.createStepExecution(ctx, projectCode, step.Execution))
m.SetSteps(c.convertStepMaps(ctx, projectCode, step.Steps))

return *m
}

func (c *ClientV2) createStepExecution(execution models.StepExecution) apiV2Client.ResultStepExecution {
func (c *ClientV2) createStepExecution(ctx context.Context, projectCode string, execution models.StepExecution) apiV2Client.ResultStepExecution {
status, _ := apiV2Client.NewResultStepStatusFromValue(execution.Status)
exec := apiV2Client.NewResultStepExecution(*status)

exec.Attachments = c.clientV1.convertAttachments(ctx, projectCode, execution.Attachments)

if execution.Duration != nil {
exec.SetDuration(int64(*execution.Duration))
}
Expand All @@ -152,7 +154,7 @@ func (c *ClientV2) convertStepMaps(ctx context.Context, projectCode string, step
for i := range steps {
stepMaps[i] = map[string]interface{}{
"data": apiV2Client.NewResultStepData(steps[i].Data.Action),
"execution": c.createStepExecution(steps[i].Execution),
"execution": c.createStepExecution(ctx, projectCode, steps[i].Execution),
"steps": c.convertStepMaps(ctx, projectCode, steps[i].Steps),
}
}
Expand Down
50 changes: 42 additions & 8 deletions internal/parsers/allure/allure.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (

// Parser is a parser for Allure files
type Parser struct {
path string
path string
rootPath string
}

// NewParser creates a new Parser
Expand All @@ -23,6 +24,23 @@ func NewParser(path string) *Parser {
}
}

var (
validStepStatuses = map[string]bool{
"passed": true,
"failed": true,
"skipped": true,
"blocked": true,
}

validTestStatuses = map[string]bool{
"passed": true,
"failed": true,
"skipped": true,
"blocked": true,
"invalid": true,
}
)

// Parse parses the Allure file and returns the results
func (p *Parser) Parse() ([]models.Result, error) {
const op = "allure.Parser.Parse"
Expand All @@ -35,6 +53,7 @@ func (p *Parser) Parse() ([]models.Result, error) {
}

if fileInfo.IsDir() {
p.rootPath = p.path
err := filepath.Walk(p.path, func(path string, info os.FileInfo, err error) error {
if err != nil {
return fmt.Errorf("failed to walk path: %w", err)
Expand All @@ -48,6 +67,7 @@ func (p *Parser) Parse() ([]models.Result, error) {
return nil, fmt.Errorf("failed to walk path: %w", err)
}
} else {
p.rootPath = filepath.Dir(p.path)
files = append(files, p.path)
}

Expand All @@ -59,7 +79,7 @@ func (p *Parser) Parse() ([]models.Result, error) {
results := make([]models.Result, 0, len(files))

for _, file := range files {
if filepath.Ext(file) != ".json" {
if !strings.Contains(file, "-result.json") {
logger.Debug("skipping file. Only support json format", "file", file)
continue
}
Expand Down Expand Up @@ -105,7 +125,7 @@ func (p *Parser) convertTest(test Test) models.Result {
Fields: map[string]string{},
Execution: models.Execution{
Duration: &d,
Status: test.Status,
Status: p.convertTestResultStatus(test.Status),
StackTrace: test.StatusDetails.Trace,
},
Message: test.StatusDetails.Message,
Expand Down Expand Up @@ -150,7 +170,7 @@ func (p *Parser) convertStep(step TestStep) models.Step {
Execution: models.StepExecution{
Attachments: p.convertAttachments(step.Attachments),
Duration: &d,
Status: step.Status,
Status: p.convertStepResultStatus(step.Status),
},
Steps: make([]models.Step, 0, len(step.Steps)),
}
Expand All @@ -166,13 +186,27 @@ func (p *Parser) convertAttachments(attachments []Attachment) []models.Attachmen
result := make([]models.Attachment, 0, len(attachments))

for _, attachment := range attachments {
d := filepath.Dir(p.path)
p := path.Join(d, attachment.Source)
p := path.Join(p.rootPath, attachment.Source)
result = append(result, models.Attachment{
Name: attachment.Name,
FilePath: &p,
Name: attachment.Name,
ContentType: attachment.Type,
FilePath: &p,
})
}

return result
}

func (p *Parser) convertTestResultStatus(status string) string {
if validTestStatuses[status] {
return status
}
return "invalid"
}

func (p *Parser) convertStepResultStatus(status string) string {
if validStepStatuses[status] {
return status
}
return "blocked"
}

0 comments on commit fa7028d

Please sign in to comment.