/
test.go
45 lines (37 loc) · 1.06 KB
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package test
import (
"fmt"
"github.com/goodhosts/cli/mage/install"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
// Unit run all unit tests
func Unit() error {
fmt.Println("Running Tests...")
return sh.RunV("go", "test")
}
// Build run a test build to confirm no compilation errors
func Build() error {
fmt.Println("Running Build...")
mg.Deps(install.Goreleaser)
return sh.RunV("goreleaser", "--clean", "--skip=validate", "--skip=publish", "--snapshot")
}
// Coverage run all unit tests and output coverage
func Coverage() error {
fmt.Println("Running Tests with Coverage...")
return sh.RunV("go", "test", "-v", "-coverprofile=coverage.txt", "./...")
}
// HTML display the html coverage report from the cover tool
func HTML() error {
if err := Coverage(); err != nil {
return err
}
return sh.RunV("go", "tool", "cover", "-html", "coverage.txt")
}
// Func display the func coverage report from the cover tool
func Func() error {
if err := Coverage(); err != nil {
return err
}
return sh.RunV("go", "tool", "cover", "-func", "coverage.txt")
}