mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-06 05:28:07 -05:00
Add test for failing test output
Cleanup parser tests. Move test output to separate files.
This commit is contained in:
parent
4b851d63d2
commit
23311beb18
@ -1,19 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOutputPass(t *testing.T) {
|
||||
testOutputPass := `=== RUN TestOne
|
||||
--- PASS: TestOne (0.06 seconds)
|
||||
=== RUN TestTwo
|
||||
--- PASS: TestTwo (0.10 seconds)
|
||||
PASS
|
||||
ok package/name 0.160s`
|
||||
type TestCase struct {
|
||||
name string
|
||||
expectedReport Report
|
||||
}
|
||||
|
||||
expected := Report{
|
||||
var testCases []TestCase = []TestCase{
|
||||
{
|
||||
name: "01-pass.txt",
|
||||
expectedReport: Report{
|
||||
Packages: []Package{
|
||||
{
|
||||
Name: "package/name",
|
||||
@ -34,9 +34,43 @@ ok package/name 0.160s`
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "02-fail.txt",
|
||||
expectedReport: Report{
|
||||
Packages: []Package{
|
||||
{
|
||||
Name: "package/name",
|
||||
Time: 151,
|
||||
Tests: []Test{
|
||||
{
|
||||
Name: "TestOne",
|
||||
Time: 20,
|
||||
Result: FAIL,
|
||||
Output: "",
|
||||
},
|
||||
{
|
||||
Name: "TestTwo",
|
||||
Time: 130,
|
||||
Result: PASS,
|
||||
Output: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
report, err := Parse(strings.NewReader(testOutputPass))
|
||||
func TestParser(t *testing.T) {
|
||||
for _, testCase := range testCases {
|
||||
file, err := os.Open("tests/" + testCase.name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
report, err := Parse(file)
|
||||
if err != nil {
|
||||
t.Fatalf("error parsing: %s", err)
|
||||
}
|
||||
@ -45,6 +79,7 @@ ok package/name 0.160s`
|
||||
t.Fatalf("Report == nil")
|
||||
}
|
||||
|
||||
expected := testCase.expectedReport
|
||||
if len(report.Packages) != len(expected.Packages) {
|
||||
t.Fatalf("Report packages == %d, want %d", len(report.Packages), len(expected.Packages))
|
||||
}
|
||||
@ -85,22 +120,4 @@ ok package/name 0.160s`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const testOutputFail = `=== RUN TestOne
|
||||
--- FAIL: TestOne (0.02 seconds)
|
||||
file_test.go:11: Error message
|
||||
file_test.go:11: Longer
|
||||
error
|
||||
message.
|
||||
=== RUN TestTwo
|
||||
--- PASS: TestTwo (0.13 seconds)
|
||||
FAIL
|
||||
exit status 1
|
||||
FAIL package/name 0.151s`
|
||||
|
||||
func TestOutputFail(t *testing.T) {
|
||||
_, err := Parse(strings.NewReader(testOutputFail))
|
||||
if err != nil {
|
||||
t.Fatalf("error parsing: %s", err)
|
||||
}
|
||||
}
|
||||
|
6
tests/01-pass.txt
Normal file
6
tests/01-pass.txt
Normal file
@ -0,0 +1,6 @@
|
||||
=== RUN TestOne
|
||||
--- PASS: TestOne (0.06 seconds)
|
||||
=== RUN TestTwo
|
||||
--- PASS: TestTwo (0.10 seconds)
|
||||
PASS
|
||||
ok package/name 0.160s
|
11
tests/02-fail.txt
Normal file
11
tests/02-fail.txt
Normal file
@ -0,0 +1,11 @@
|
||||
=== RUN TestOne
|
||||
--- FAIL: TestOne (0.02 seconds)
|
||||
file_test.go:11: Error message
|
||||
file_test.go:11: Longer
|
||||
error
|
||||
message.
|
||||
=== RUN TestTwo
|
||||
--- PASS: TestTwo (0.13 seconds)
|
||||
FAIL
|
||||
exit status 1
|
||||
FAIL package/name 0.151s
|
Loading…
x
Reference in New Issue
Block a user