-
Notifications
You must be signed in to change notification settings - Fork 291
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
magefile: added combined test coverage support for mage test:all
#2235
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Kartikay <[email protected]>
magefiles/util.go
Outdated
testArgs := append([]string{ | ||
"test", | ||
"-covermode=atomic", | ||
"-coverprofile=coverage.txt", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this overwrite the coverage.txt file when each individual test suite runs? Can you try running mage test:all
and ensure it combines the coverage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: Kartikay <[email protected]>
46942c5
to
64f1377
Compare
magefiles/util.go
Outdated
@@ -210,3 +223,45 @@ func run(dir string, env map[string]string, stdout, stderr io.Writer, cmd string | |||
err = c.Run() | |||
return sh.CmdRan(err), sh.ExitStatus(err), err | |||
} | |||
|
|||
func sanitizePath(path string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend hashing the path here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Signed-off-by: Kartikay <[email protected]>
ba7d1da
to
59fd80d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the PR enables coverage by default on all
, whereas before it was opt in. Do we have concerns that would add overhead on the inner loop? Or is the overhead negligible?
4fb47db
to
7498752
Compare
Signed-off-by: Kartikay <[email protected]>
7498752
to
3f62b00
Compare
I used |
} | ||
defer f.Close() | ||
|
||
args := []string{"run", "github.com/wadey/gocovmerge@latest"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use go tool covdata merge
, see https://go.dev/doc/build-cover
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems we need to build a binary for this for specifying the -cover
flag before the tests which would generate the files(tests should be carried on the same binary?)
magefiles/util.go
Outdated
@@ -210,3 +221,40 @@ func run(dir string, env map[string]string, stdout, stderr io.Writer, cmd string | |||
err = c.Run() | |||
return sh.CmdRan(err), sh.ExitStatus(err), err | |||
} | |||
|
|||
func hashPath(path string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to hash the path? I'd keep it simpler by generating a UUID as suffix
magefiles/test.go
Outdated
func (t Test) AllCover() error { | ||
ds := Testds{} | ||
c := Testcons{} | ||
mg.Deps(t.UnitCover, t.IntegrationCover, t.SteelthreadCover, t.ImageCover, t.AnalyzersCover, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems like a lot of duplication that would lead to drift w.r.t to All()
method. Ideally All
and AllCover
invoke `all(coverage bool)
magefiles/util.go
Outdated
return err | ||
} | ||
|
||
for _, file := range files { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why deleting the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was for deleting individual coverage files after merging them. reverting
magefiles/test.go
Outdated
"-tags", "ci,docker,datastoreconsistency", | ||
"-timeout", "10m", | ||
"-run", fmt.Sprintf("TestConsistencyPerDatastore/%s", datastore)) | ||
if coverage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all this if coverage
blocks could be refactored to avoid all the duplication - e.g. a function that takes the args
and the coverage
bool, and returns the args with the appended parameters.
magefiles/test.go
Outdated
|
||
func (Testds) spanner(coverage bool) error { | ||
args := []string{"-tags", "ci,docker", "-timeout", "10m"} | ||
if coverage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lots of duplication: this coverage
if statement should be handled inside datastoreTest
magefiles/test.go
Outdated
func (Test) image(coverage bool) error { | ||
mg.Deps(Build{}.Testimage) | ||
args := []string{"-tags", "docker,image"} | ||
if coverage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be moved into goDirTest
, otherwise it leads to a lot of duplication
magefiles/test.go
Outdated
@@ -43,27 +53,75 @@ func (Test) unit(coverage bool) error { | |||
fmt.Println("running unit tests") | |||
args := []string{"-tags", "ci,skipintegrationtests", "-race", "-timeout", "10m", "-count=1"} | |||
if coverage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be moved into goTest
, otherwise it leads to a lot of duplication
magefiles/test.go
Outdated
} | ||
|
||
// SteelthreadCover Runs the steelthread tests and generates a coverage report | ||
func (t Test) SteelthreadCover() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's annoying we end up with proliferation of commands just to have with/without coverage versions of them. Calling mage
leads to a very long list that starts to become not very user friendly.
I know mage supports arguments in commands, but not if it supports commands with arguments and default values, could you investigate?
Signed-off-by: Kartikay <[email protected]>
Utilised uuid instead, also passed the bool through a context to |
Fixes #1348
mage test:all
now generates combined coverprofile aggregated intocoverage.txt