-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: junit xml * feat: xml jtl format support * fix: condition tuning * fix: test fake site * fix: unit tests * Revert "fix: test fake site" This reverts commit 03a3242. * Revert "Revert "fix: test fake site"" This reverts commit 2697568. * Revert "Revert "Revert "fix: test fake site""" This reverts commit 00fe235.
- Loading branch information
Showing
7 changed files
with
249 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package parser | ||
|
||
import ( | ||
"encoding/xml" | ||
) | ||
|
||
// TestResults is a root element of junit xml report | ||
type TestResults struct { | ||
XMLName xml.Name `xml:"testResults"` | ||
HTTPSamples []HTTPSample `xml:"httpSample,omitempty"` | ||
} | ||
|
||
// HTTPSample is http sample details | ||
type HTTPSample struct { | ||
XMLName xml.Name `xml:"httpSample"` | ||
Time int `xml:"t,attr"` | ||
Success bool `xml:"s,attr"` | ||
Label string `xml:"lb,attr"` | ||
ResponseCode string `xml:"rc,attr"` | ||
AssertionResult *AssertionResult `xml:"assertionResult"` | ||
} | ||
|
||
// AssertionResult contains assertion | ||
type AssertionResult struct { | ||
XMLName xml.Name `xml:"assertionResult"` | ||
Name string `xml:"name"` | ||
Failure bool `xml:"failure"` | ||
Error bool `xml:"error"` | ||
FailureMessage string `xml:"failureMessage"` | ||
} | ||
|
||
func ParseXML(data []byte) (results TestResults, err error) { | ||
err = xml.Unmarshal(data, &results) | ||
|
||
return results, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package parser | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const ( | ||
badXML = ` | ||
12345 | ||
` | ||
|
||
successXML = ` | ||
<testResults version="1.2"> | ||
<httpSample t="1259" it="0" lt="124" ct="80" ts="1690288938130" s="true" lb="Testkube - HTTP Request" rc="200" rm="OK" tn="Thread Group 1-1" dt="text" by="65222" sby="366" ng="1" na="1"> | ||
<assertionResult> | ||
<name>Response Assertion</name> | ||
<failure>false</failure> | ||
<error>false</error> | ||
</assertionResult> | ||
</httpSample> | ||
</testResults> | ||
` | ||
|
||
failedXML = ` | ||
<testResults version="1.2"> | ||
<httpSample t="51" it="0" lt="0" ct="51" ts="1690366471701" s="false" lb="Testkube - HTTP Request" rc="Non HTTP response code: java.net.UnknownHostException" rm="Non HTTP response message: testkube.fakeshop.io: Name does not resolve" tn="Thread Group 1-1" dt="text" by="2327" sby="0" ng="1" na="1"> | ||
<assertionResult> | ||
<name>Response Assertion</name> | ||
<failure>true</failure> | ||
<error>false</error> | ||
<failureMessage>Test failed: code expected to equal / ****** received : [[[Non HTTP response code: java.net.UnknownHostException]]] ****** comparison: [[[200 ]]] /</failureMessage> | ||
</assertionResult> | ||
</httpSample> | ||
</testResults> | ||
` | ||
) | ||
|
||
func TestParseXML(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("parse XML success test", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
results, err := ParseXML([]byte(successXML)) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, 1, len(results.HTTPSamples)) | ||
assert.True(t, results.HTTPSamples[0].Success) | ||
assert.Equal(t, 1259, results.HTTPSamples[0].Time) | ||
assert.Equal(t, "Testkube - HTTP Request", results.HTTPSamples[0].Label) | ||
assert.Equal(t, "Response Assertion", results.HTTPSamples[0].AssertionResult.Name) | ||
}) | ||
|
||
t.Run("parse XML failed test", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
results, err := ParseXML([]byte(failedXML)) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, 1, len(results.HTTPSamples)) | ||
assert.False(t, results.HTTPSamples[0].Success) | ||
assert.Equal(t, 51, results.HTTPSamples[0].Time) | ||
assert.Equal(t, "Testkube - HTTP Request", results.HTTPSamples[0].Label) | ||
assert.Equal(t, "Test failed: code expected to equal / ****** received : [[[Non HTTP response code: java.net.UnknownHostException]]] ****** comparison: [[[200 ]]] /", results.HTTPSamples[0].AssertionResult.FailureMessage) | ||
}) | ||
|
||
t.Run("parse bad XML", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
_, err := ParseXML([]byte(badXML)) | ||
|
||
assert.EqualError(t, err, "EOF") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package parser | ||
|
||
import ( | ||
"encoding/xml" | ||
) | ||
|
||
// Testsuites is a root element of junit report | ||
type Testsuites struct { | ||
XMLName xml.Name `xml:"testsuites"` | ||
Testsuites []Testsuite `xml:"testsuite,omitempty"` | ||
Name string `xml:"name,attr,omitempty"` | ||
Tests int `xml:"tests,attr,omitempty"` | ||
Failures int `xml:"failures,attr,omitempty"` | ||
Errors int `xml:"errors,attr,omitempty"` | ||
Skipped int `xml:"skipped,attr,omitempty"` | ||
Assertions int `xml:"assertions,attr,omitempty"` | ||
Time float32 `xml:"time,attr,omitempty"` | ||
Timestamp string `xml:"timestamp,attr,omitempty"` | ||
} | ||
|
||
// Testsuite contains testsuite definition | ||
type Testsuite struct { | ||
XMLName xml.Name `xml:"testsuite"` | ||
Testcases []Testcase `xml:"testcase"` | ||
Name string `xml:"name,attr"` | ||
Tests int `xml:"tests,attr"` | ||
Failures int `xml:"failures,attr"` | ||
Errors int `xml:"errors,attr"` | ||
Skipped int `xml:"skipped,attr,omitempty"` | ||
Assertions int `xml:"assertions,attr,omitempty"` | ||
Time float32 `xml:"time,attr"` | ||
Timestamp string `xml:"timestamp,attr,omitempty"` | ||
File string `xml:"file,attr,omitempty"` | ||
} | ||
|
||
// TestResult represents the result of a testcase | ||
type TestResult struct { | ||
Message string `xml:"message,attr"` | ||
Type string `xml:"type,attr,omitempty"` | ||
} | ||
|
||
// Testcase define a testcase | ||
type Testcase struct { | ||
XMLName xml.Name `xml:"testcase"` | ||
Name string `xml:"name,attr"` | ||
ClassName string `xml:"classname,attr"` | ||
Assertions int `xml:"assertions,attr,omitempty"` | ||
Time float32 `xml:"time,attr,omitempty"` | ||
File string `xml:"file,attr,omitempty"` | ||
Line int `xml:"line,attr,omitempty"` | ||
Skipped *TestResult `xml:"skipped,omitempty"` | ||
Failure *TestResult `xml:"failure,omitempty"` | ||
Error *TestResult `xml:"error,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters