Skip to content

Commit

Permalink
feat(cli): show trace ID on failed tests (#2995)
Browse files Browse the repository at this point in the history
  • Loading branch information
schoren authored Jul 28, 2023
1 parent f9e4bc2 commit f984d51
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cli/formatters/test_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (f testRun) formatSuccessfulTest(test openapi.Test, run openapi.TestRun) st
var buffer bytes.Buffer

link := f.GetRunLink(test.GetId(), run.GetId())
message := f.formatMessage("%s %s (%s)\n", PASSED_TEST_ICON, *test.Name, link)
message := f.formatMessage("%s %s (%s) - trace id: %s\n", PASSED_TEST_ICON, *test.Name, link, run.GetTraceId())
message = f.getColoredText(true, message)
buffer.WriteString(message)

Expand Down Expand Up @@ -141,7 +141,7 @@ func (f testRun) formatFailedTest(test openapi.Test, run openapi.TestRun) string
var buffer bytes.Buffer

link := f.GetRunLink(test.GetId(), run.GetId())
message := f.formatMessage("%s %s (%s)\n", FAILED_TEST_ICON, *test.Name, link)
message := f.formatMessage("%s %s (%s) - trace id: %s\n", FAILED_TEST_ICON, test.GetName(), link, run.GetTraceId())
message = f.getColoredText(false, message)
buffer.WriteString(message)
for i, specResult := range run.Result.Results {
Expand Down
24 changes: 14 additions & 10 deletions cli/formatters/test_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ func TestSuccessfulTestRunOutput(t *testing.T) {
Name: openapi.PtrString("Testcase 1"),
},
Run: openapi.TestRun{
Id: openapi.PtrString("1"),
State: openapi.PtrString("FINISHED"),
Id: openapi.PtrString("1"),
State: openapi.PtrString("FINISHED"),
TraceId: openapi.PtrString("cb5e80748cc06f8a63f6b96c056defec"),
Result: &openapi.AssertionResults{
AllPassed: openapi.PtrBool(true),
},
Expand All @@ -53,7 +54,7 @@ func TestSuccessfulTestRunOutput(t *testing.T) {
formatter := formatters.TestRun(baseURL, false)
output := formatter.Format(in, formatters.Pretty)

assert.Equal(t, "✔ Testcase 1 (http://localhost:11633/test/9876543/run/1/test)\n", output)
assert.Equal(t, "✔ Testcase 1 (http://localhost:11633/test/9876543/run/1/test) - trace id: cb5e80748cc06f8a63f6b96c056defec\n", output)
}

func TestSuccessfulTestRunOutputWithResult(t *testing.T) {
Expand All @@ -71,8 +72,9 @@ func TestSuccessfulTestRunOutputWithResult(t *testing.T) {
},
},
Run: openapi.TestRun{
Id: openapi.PtrString("1"),
State: openapi.PtrString("FINISHED"),
Id: openapi.PtrString("1"),
TraceId: openapi.PtrString("cb5e80748cc06f8a63f6b96c056defec"),
State: openapi.PtrString("FINISHED"),
Result: &openapi.AssertionResults{
AllPassed: openapi.PtrBool(true),
Results: []openapi.AssertionResultsResultsInner{
Expand Down Expand Up @@ -101,7 +103,7 @@ func TestSuccessfulTestRunOutputWithResult(t *testing.T) {
}
formatter := formatters.TestRun(baseURL, false)
output := formatter.Format(in, formatters.Pretty)
expectedOutput := `✔ Testcase 1 (http://localhost:11633/test/9876543/run/1/test)
expectedOutput := `✔ Testcase 1 (http://localhost:11633/test/9876543/run/1/test) - trace id: cb5e80748cc06f8a63f6b96c056defec
✔ Validate span duration
`

Expand All @@ -126,7 +128,8 @@ func TestFailingTestOutput(t *testing.T) {
},
},
Run: openapi.TestRun{
Id: openapi.PtrString("1"),
Id: openapi.PtrString("1"),
TraceId: openapi.PtrString("cb5e80748cc06f8a63f6b96c056defec"),
Result: &openapi.AssertionResults{
AllPassed: openapi.PtrBool(false),
Results: []openapi.AssertionResultsResultsInner{
Expand Down Expand Up @@ -187,7 +190,7 @@ func TestFailingTestOutput(t *testing.T) {

formatter := formatters.TestRun(baseURL, false)
output := formatter.Format(in, formatters.Pretty)
expectedOutput := `✘ Testcase 2 (http://localhost:11633/test/9876543/run/1/test)
expectedOutput := `✘ Testcase 2 (http://localhost:11633/test/9876543/run/1/test) - trace id: cb5e80748cc06f8a63f6b96c056defec
✔ Validate span duration
✔ #123456
✔ attr:tracetest.span.duration <= 200ms (157ms)
Expand Down Expand Up @@ -217,7 +220,8 @@ func TestFailingTestOutputWithPadding(t *testing.T) {
},
},
Run: openapi.TestRun{
Id: openapi.PtrString("1"),
Id: openapi.PtrString("1"),
TraceId: openapi.PtrString("cb5e80748cc06f8a63f6b96c056defec"),
Result: &openapi.AssertionResults{
AllPassed: openapi.PtrBool(false),
Results: []openapi.AssertionResultsResultsInner{
Expand Down Expand Up @@ -278,7 +282,7 @@ func TestFailingTestOutputWithPadding(t *testing.T) {

formatter := formatters.TestRun(baseURL, false, formatters.WithPadding(1))
output := formatter.Format(in, formatters.Pretty)
expectedOutput := ` ✘ Testcase 2 (http://localhost:11633/test/9876543/run/1/test)
expectedOutput := ` ✘ Testcase 2 (http://localhost:11633/test/9876543/run/1/test) - trace id: cb5e80748cc06f8a63f6b96c056defec
✔ Validate span duration
✔ #123456
✔ attr:tracetest.span.duration <= 200ms (157ms)
Expand Down

0 comments on commit f984d51

Please sign in to comment.