go-junit-report/pkg/gtr/gtr_test.go
2022-03-07 00:09:34 +00:00

40 lines
886 B
Go

package gtr
import (
"testing"
"time"
"github.com/jstemmer/go-junit-report/v2/pkg/parser/gotest"
"github.com/google/go-cmp/cmp"
)
func TestFromEvents(t *testing.T) {
events := []gtop.Event{
{Type: "run_test", Id: 1, Name: "TestOne"},
{Type: "end_test", Id: 1, Name: "TestOne", Result: "PASS", Duration: 1 * time.Millisecond},
{Type: "status", Result: "PASS"},
{Type: "summary", Result: "ok", Name: "package/name", Duration: 1 * time.Millisecond},
}
expected := Report{
Packages: []Package{
{
Name: "package/name",
Duration: 1 * time.Millisecond,
Tests: []Test{
{
Name: "TestOne",
Duration: 1 * time.Millisecond,
Result: PASS,
},
},
},
},
}
actual := FromEvents(events)
if diff := cmp.Diff(actual, expected); diff != "" {
t.Errorf("FromEvents report incorrect, diff (-got, +want):\n%v", diff)
}
}