-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Brian Goff <[email protected]>
- Loading branch information
Showing
7 changed files
with
205 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
// TestEvent is the go test2json event data structure we receive from `go test` | ||
// This is defined in https://pkg.go.dev/cmd/test2json#hdr-Output_Format | ||
type TestEvent struct { | ||
Time time.Time | ||
Action string | ||
Package string | ||
Test string | ||
Elapsed float64 // seconds | ||
Output string | ||
} | ||
|
||
// TestResult is where we collect all the data about a test | ||
type TestResult struct { | ||
output *os.File | ||
failed bool | ||
pkg string | ||
name string | ||
elapsed float64 | ||
skipped bool | ||
} | ||
|
||
func (r *TestResult) Close() { | ||
r.output.Close() | ||
} | ||
|
||
func handlEvent(te *TestEvent, tr *TestResult) error { | ||
if te.Output != "" { | ||
_, err := tr.output.Write([]byte(te.Output)) | ||
if err != nil { | ||
return errors.Wrap(err, "error collecting test event output") | ||
} | ||
} | ||
|
||
tr.pkg = te.Package | ||
tr.name = te.Test | ||
if te.Elapsed > 0 { | ||
tr.elapsed = te.Elapsed | ||
} | ||
|
||
if te.Action == "fail" { | ||
tr.failed = true | ||
} | ||
if te.Action == "skip" { | ||
tr.skipped = true | ||
} | ||
return nil | ||
} |
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,26 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestFail(t *testing.T) { | ||
t.Log("This is for checking what a test failure looks like") | ||
t.Fatal("This is a failure") | ||
} | ||
|
||
func TestAnotherFail(t *testing.T) { | ||
t.Log("This is for checking what a test failure looks like") | ||
t.Fatal("This is yet another failure!") | ||
} | ||
|
||
func TestSlow(t *testing.T) { | ||
time.Sleep(10 * time.Second) | ||
t.Log("This is a slow test!") | ||
} | ||
|
||
func TestAnothrSlow(t *testing.T) { | ||
time.Sleep(5 * time.Second) | ||
t.Log("This is yet another slow test!") | ||
} |
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,34 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"strings" | ||
) | ||
|
||
func mdBold(v string) string { | ||
return "**" + v + "**" | ||
} | ||
|
||
func mdDetails(s string) string { | ||
return fmt.Sprintf("\n<details>\n%s\n</details>\n", s) | ||
} | ||
|
||
func mdSummary(s string) string { | ||
return "<summary>" + s + "</summary>\n" | ||
} | ||
|
||
func mdPreformat(s string) string { | ||
return fmt.Sprintf("\n```\n%s\n```\n", s) | ||
} | ||
|
||
type nopWriteCloser struct { | ||
io.Writer | ||
} | ||
|
||
func mdLog(head string, content fmt.Stringer) string { | ||
sb := &strings.Builder{} | ||
sb.WriteString(mdSummary(head)) | ||
sb.WriteString(mdPreformat(content.String())) | ||
return mdDetails(sb.String()) | ||
} |
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