Skip to content

Commit

Permalink
added test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Kartikay <[email protected]>
  • Loading branch information
kartikaysaxena committed Feb 4, 2025
1 parent abdb041 commit 80503bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
11 changes: 2 additions & 9 deletions magefiles/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Test mg.Namespace

var emptyEnv map[string]string

// All Runs all test suites
// All Runs all test suites and generates a combined coverage report
func (t Test) All() error {
ds := Testds{}
c := Testcons{}
Expand All @@ -27,7 +27,7 @@ func (t Test) All() error {

// UnitCover Runs the unit tests and generates a coverage report
func (t Test) UnitCover() error {
if err := t.unit(true); err != nil {
if err := t.Unit(); err != nil {
return err
}
fmt.Println("Running coverage...")
Expand All @@ -36,15 +36,8 @@ func (t Test) UnitCover() error {

// Unit Runs the unit tests
func (t Test) Unit() error {
return t.unit(false)
}

func (Test) unit(coverage bool) error {
fmt.Println("running unit tests")
args := []string{"-tags", "ci,skipintegrationtests", "-race", "-timeout", "10m", "-count=1"}
if coverage {
args = append(args, "-covermode=atomic", "-coverprofile=coverage.txt")
}
return goTest("./...", args...)
}

Expand Down
16 changes: 14 additions & 2 deletions magefiles/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,24 @@ func goTest(path string, args ...string) error {

// run go test in a directory
func goDirTest(dir string, path string, args ...string) error {
testArgs := append([]string{"test", "-failfast", "-count=1"}, args...)
testArgs := append([]string{
"test",
"-covermode=atomic",
"-coverprofile=coverage.txt",
"-failfast",
"-count=1",
}, args...)
return RunSh(goCmdForTests(), WithV(), WithDir(dir), WithArgs(testArgs...))(path)
}

func goDirTestWithEnv(dir string, path string, env map[string]string, args ...string) error {
testArgs := append([]string{"test", "-failfast", "-count=1"}, args...)
testArgs := append([]string{
"test",
"-covermode=atomic",
"-coverprofile=coverage.txt",
"-failfast",
"-count=1",
}, args...)
return RunSh(goCmdForTests(), WithV(), WithDir(dir), WithEnv(env), WithArgs(testArgs...))(path)
}

Expand Down

0 comments on commit 80503bb

Please sign in to comment.