Skip to content

Commit

Permalink
Add TestCase.Time
Browse files Browse the repository at this point in the history
Time is copied from the Action=run TestEvent
  • Loading branch information
dnephin committed Nov 8, 2020
1 parent 700bc79 commit af85a09
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions testjson/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ type TestCase struct {
// hasSubTestFailed is true when a subtest of this TestCase has failed. It is
// used to find root TestCases which have no failing subtests.
hasSubTestFailed bool
// Time when the test was run.
Time time.Time
}

func newPackage() *Package {
Expand Down Expand Up @@ -307,6 +309,7 @@ func (p *Package) newTestCaseFromEvent(event TestEvent) TestCase {
Test: TestName(event.Test),
ID: p.Total,
RunID: event.RunID,
Time: event.Time,
}
}

Expand Down
17 changes: 17 additions & 0 deletions testjson/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,20 @@ func (s *handlerFails) Event(_ TestEvent, _ *Execution) error {
func (s *handlerFails) Err(_ string) error {
return nil
}

func TestParseEvent(t *testing.T) {
// nolint: lll
raw := `{"Time":"2018-03-22T22:33:35.168308334Z","Action":"output","Package":"example.com/good","Test": "TestOk","Output":"PASS\n"}`
event, err := parseEvent([]byte(raw))
assert.NilError(t, err)
expected := TestEvent{
Time: time.Date(2018, 3, 22, 22, 33, 35, 168308334, time.UTC),
Action: "output",
Package: "example.com/good",
Test: "TestOk",
Output: "PASS\n",
raw: []byte(raw),
}
cmpTestEvent := cmp.AllowUnexported(TestEvent{})
assert.DeepEqual(t, event, expected, cmpTestEvent)
}

0 comments on commit af85a09

Please sign in to comment.