Start adding test command
This commit is contained in:
parent
67bb74abf4
commit
681e5f2955
60
magefile.go
60
magefile.go
|
@ -19,6 +19,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/magefile/mage/mg"
|
||||
"os"
|
||||
|
@ -43,6 +44,7 @@ var (
|
|||
Version = "master" // This holds the built version, master by default, when building from a tag or release branch, their name
|
||||
BinLocation = ""
|
||||
PkgVersion = "master"
|
||||
ApiPackages = []string{}
|
||||
)
|
||||
|
||||
func setVersion() {
|
||||
|
@ -83,15 +85,63 @@ func setExecutable() {
|
|||
}
|
||||
}
|
||||
|
||||
func setApiPackages() {
|
||||
cmd := exec.Command("go", "list", "all")
|
||||
pkgs, err := cmd.Output()
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting packages: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
for _, p := range strings.Split(string(pkgs), "\n") {
|
||||
if strings.Contains(p, "code.vikunja.io/api") && !strings.Contains(p, "code.vikunja.io/api/pkg/integrations") {
|
||||
ApiPackages = append(ApiPackages, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func setRootPath() {
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting pwd: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := os.Setenv("VIKUNJA_SERVICE_ROOTPATH", pwd); err != nil {
|
||||
fmt.Printf("Error setting root path: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
Tags = os.Getenv("TAGS")
|
||||
setVersion()
|
||||
setExecutable()
|
||||
setBinLocation()
|
||||
setPkgVersion()
|
||||
setApiPackages()
|
||||
setRootPath()
|
||||
Ldflags = `-X "` + PACKAGE + `/pkg/version.VersionNumber=` + VersionNumber + `" -X "main.Tags=` + Tags + `"`
|
||||
}
|
||||
|
||||
func runAndStreamOutput(cmd string, args ...string) {
|
||||
c := exec.Command(cmd, args...)
|
||||
|
||||
c.Env = os.Environ()
|
||||
|
||||
fmt.Printf("%s\n\n", c.String())
|
||||
|
||||
stdout, _ := c.StdoutPipe()
|
||||
c.Start()
|
||||
|
||||
reader := bufio.NewReader(stdout)
|
||||
line, err := reader.ReadString('\n')
|
||||
for err == nil {
|
||||
fmt.Println(line)
|
||||
line, err = reader.ReadString('\n')
|
||||
}
|
||||
|
||||
c.Wait()
|
||||
}
|
||||
|
||||
// Clean all build, executable and bindata files.
|
||||
func Clean() error {
|
||||
if err := exec.Command("go", "clean", "./...").Run(); err != nil {
|
||||
|
@ -110,7 +160,15 @@ func Clean() error {
|
|||
}
|
||||
|
||||
func Test() {
|
||||
|
||||
// We run everything sequentially and not in parallel to prevent issues with real test databases
|
||||
// VIKUNJA_SERVICE_ROOTPATH=$(shell pwd) go test $(GOFLAGS) -p 1 -cover -coverprofile cover.out $(PACKAGES)
|
||||
args := []string{"test", Goflags[0], "-p 1"}
|
||||
args = append(args, ApiPackages...)
|
||||
runAndStreamOutput("go", args...)
|
||||
//for _, a := range ApiPackages {
|
||||
// args[len(args)-1] = a
|
||||
// runAndStreamOutput("go", args...)
|
||||
//}
|
||||
}
|
||||
|
||||
func TestCoverage() {
|
||||
|
|
Loading…
Reference in New Issue