Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run unit and integration tests with gotestsum #22541

Merged
merged 34 commits into from
Jan 14, 2021
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d35fd1c
Creating failing tests, test cases
Nov 11, 2020
b629d7b
Rewrite mage go test based on gotestsum
Nov 16, 2020
81a34eb
Merge branch 'master' into test_reports_incomplete
Nov 16, 2020
13b252b
Fix lint on tests
Nov 18, 2020
9d8e563
print go test output directly
Nov 18, 2020
747a429
clean up go.mod after installing go based tool
Nov 18, 2020
53717ea
Merge branch 'master' into test_reports_incomplete
Nov 19, 2020
4f7cb68
lets try with go get
Nov 19, 2020
0b98e70
try to switch to another directory before when installing gotestsum
Nov 20, 2020
7629ccb
Add gotestsum to heartbeat docker image for testing
Nov 20, 2020
2170d7e
fix verbosity mode
Dec 8, 2020
6e659b9
Merge branch 'master' into test_reports_incomplete
Dec 8, 2020
d2eff71
remove leftover debug output
Dec 9, 2020
1f3c661
Merge branch 'master' into test_reports_incomplete
Dec 24, 2020
8268937
Add gotestsum to metricbeat dockerfile
Dec 24, 2020
d5af77d
Merge branch 'master' into test_reports_incomplete
Dec 28, 2020
c576b27
Add missing gotestsum to Dockerfiles
Dec 28, 2020
c1ddf3f
Add unit tests for GoTest
Dec 29, 2020
91a86ed
remove test output tests from filebeat
Dec 29, 2020
e4a7dfc
fix notice file
Dec 29, 2020
ac578cb
Update common/cli tests to capture output as well
Dec 30, 2020
2d7b0e3
one more missing gotestsum
Dec 30, 2020
f393fdf
Do not upgrade x/sys
Dec 30, 2020
c567e11
use go.mod from master
Dec 30, 2020
a06fcd2
gotest testing cleanups and minor fixes
Dec 30, 2020
6448cb2
remove GoTestSummary
Jan 4, 2021
b015a84
Merge branch 'master' into test_reports_incomplete
Jan 4, 2021
e61ea51
Merge branch 'master' into test_reports_incomplete
Jan 12, 2021
942f413
remove go-junit-reporter from go.mod
Jan 12, 2021
5cabf71
update notice
Jan 12, 2021
e75a323
Install gotestsum via mage
Jan 12, 2021
28de5cc
Merge branch 'master' into test_reports_incomplete
Jan 12, 2021
703fcf5
fix import order
Jan 13, 2021
69b3387
Try to fix build by updating indirect dependency psutil
Jan 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove GoTestSummary
  • Loading branch information
urso committed Jan 4, 2021
commit 6448cb2c6f61db00cf6d791affea6b5c62d28f2a
110 changes: 0 additions & 110 deletions dev-tools/mage/gotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ import (
"os/exec"
"path"
"path/filepath"
"sort"
"strings"
"time"

"github.com/jstemmer/go-junit-report/parser"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/pkg/errors"
Expand Down Expand Up @@ -323,114 +321,6 @@ func makeCommand(ctx context.Context, env map[string]string, cmd string, args ..
return c
}

// GoTestSummary is a summary of test results.
type GoTestSummary struct {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GoTestSummary is not used anymore. gotestsum prints it's own summary, not as rich as this one, but should be good enough.

*parser.Report // Report generated by parsing test output.
Pass int // Number of passing tests.
Fail int // Number of failed tests.
Skip int // Number of skipped tests.
Packages int // Number of packages tested.
Duration time.Duration // Total go test running duration.
Files map[string]string
}

// NewGoTestSummary builds a new GoTestSummary. It returns an error if it cannot
// resolve the absolute paths to the given files.
func NewGoTestSummary(d time.Duration, r *parser.Report, outputFiles map[string]string) (*GoTestSummary, error) {
files := map[string]string{}
for name, file := range outputFiles {
if file == "" {
continue
}
absFile, err := filepath.Abs(file)
if err != nil {
return nil, errors.Wrapf(err, "failed resolving absolute path for %v", file)
}
files[name+":"] = absFile
}

summary := &GoTestSummary{
Report: r,
Duration: d,
Packages: len(r.Packages),
Files: files,
}

for _, pkg := range r.Packages {
for _, t := range pkg.Tests {
switch t.Result {
case parser.PASS:
summary.Pass++
case parser.FAIL:
summary.Fail++
case parser.SKIP:
summary.Skip++
default:
return nil, errors.Errorf("Unknown test result value: %v", t.Result)
}
}
}

return summary, nil
}

// Failures returns a string containing the list of failed test cases and their
// output.
func (s *GoTestSummary) Failures() string {
b := new(strings.Builder)

if s.Fail > 0 {
fmt.Fprintln(b, "FAILURES:")
for _, pkg := range s.Report.Packages {
for _, t := range pkg.Tests {
if t.Result != parser.FAIL {
continue
}
fmt.Fprintln(b, "Package:", pkg.Name)
fmt.Fprintln(b, "Test: ", t.Name)
for _, line := range t.Output {
if strings.TrimSpace(line) != "" {
fmt.Fprintln(b, line)
}
}
fmt.Fprintln(b, "----")
}
}
}

return strings.TrimRight(b.String(), "\n")
}

// String returns a summary of the testing results (number of fail/pass/skip,
// test duration, number packages, output files).
func (s *GoTestSummary) String() string {
b := new(strings.Builder)

fmt.Fprintln(b, "SUMMARY:")
fmt.Fprintln(b, " Fail: ", s.Fail)
fmt.Fprintln(b, " Skip: ", s.Skip)
fmt.Fprintln(b, " Pass: ", s.Pass)
fmt.Fprintln(b, " Packages:", len(s.Report.Packages))
fmt.Fprintln(b, " Duration:", s.Duration)

// Sort the list of files and compute the column width.
var names []string
var nameWidth int
for name := range s.Files {
if len(name) > nameWidth {
nameWidth = len(name)
}
names = append(names, name)
}
sort.Strings(names)

for _, name := range names {
fmt.Fprintf(b, " %-*s %s\n", nameWidth, name, s.Files[name])
}

return strings.TrimRight(b.String(), "\n")
}

// BuildSystemTestBinary runs BuildSystemTestGoBinary with default values.
func BuildSystemTestBinary() error {
return BuildSystemTestGoBinary(DefaultTestBinaryArgs())
Expand Down