-
Notifications
You must be signed in to change notification settings - Fork 129
add Elastic Stack and Elastic Package version to test results report #3070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
c580a91
e258efe
9800164
44babb7
9354a4c
f9c24e2
c0d5ac6
a1e4184
64b4c8d
692ae30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License; | ||
| // you may not use this file except in compliance with the Elastic License. | ||
|
|
||
| package formats | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/elastic/elastic-package/internal/testrunner" | ||
| ) | ||
|
|
||
| func init() { | ||
| testrunner.RegisterReporterFormat(ReportFormatJSON, reportJSONFormat) | ||
| } | ||
|
|
||
| const ( | ||
| // ReportFormatJSON reports test results in a JSON format | ||
| ReportFormatJSON testrunner.TestReportFormat = "json" | ||
| ) | ||
|
|
||
| type jsonResult struct { | ||
| Package string `json:"package"` | ||
| DataStream string `json:"data_stream,omitempty"` | ||
| TestType string `json:"test_type"` | ||
| Name string `json:"name"` | ||
| Result string `json:"result"` | ||
| TimeElapsed string `json:"time_elapsed"` | ||
| FailureDetails string `json:"failure_details,omitempty"` | ||
| } | ||
|
|
||
| func reportJSONFormat(results []testrunner.TestResult) (string, error) { | ||
| if len(results) == 0 { | ||
| return "No test results", nil | ||
| } | ||
|
|
||
| jsonReport := make([]jsonResult, 0, len(results)) | ||
| for _, r := range results { | ||
| jsonResult := jsonResult{ | ||
| Package: r.Package, | ||
| DataStream: r.DataStream, | ||
| TestType: string(r.TestType), | ||
| Name: r.Name, | ||
| TimeElapsed: r.TimeElapsed.String(), | ||
| } | ||
|
|
||
| if r.FailureMsg != "" { | ||
| jsonResult.FailureDetails = fmt.Sprintf("%s/%s %s:\n%s\n", r.Package, r.DataStream, r.Name, r.FailureDetails) | ||
| } | ||
|
|
||
| var result string | ||
| if r.ErrorMsg != "" { | ||
| result = fmt.Sprintf("ERROR: %s", r.ErrorMsg) | ||
| } else if r.FailureMsg != "" { | ||
| result = fmt.Sprintf("FAIL: %s", r.FailureMsg) | ||
| } else if r.Skipped != nil { | ||
| result = fmt.Sprintf("SKIPPED: %s", r.Skipped.String()) | ||
| } else { | ||
| result = "PASS" | ||
| } | ||
| jsonResult.Result = result | ||
|
|
||
| jsonReport = append(jsonReport, jsonResult) | ||
| } | ||
|
|
||
| b, err := json.Marshal(jsonReport) | ||
| if err != nil { | ||
| return "", fmt.Errorf("marshaling test results to JSON: %w", err) | ||
| } | ||
| return string(b), nil | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,8 +39,11 @@ func reportToFile(pkg, report string, testType testrunner.TestType, format testr | |
| } | ||
|
|
||
| ext := "txt" | ||
| if format == formats.ReportFormatXUnit { | ||
| switch format { | ||
| case formats.ReportFormatXUnit: | ||
| ext = "xml" | ||
| case formats.ReportFormatJSON: | ||
| ext = "json" | ||
|
||
| } | ||
|
|
||
| fileName := fmt.Sprintf("%s-%s-%d.%s", pkg, testType, time.Now().UnixNano(), ext) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is printed by each test action, this is printed multiple times, once for each type of test, when running
elastic-package testwithout specifying a subcommand. Is this intended?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is intentional, as the version from the stack is taken from the clients / profile.
would it make sense to create a esClient right at the begining of the test cmd to get the version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, as not all tests need it. Let's leave it here by now.