refactor: use Go idioms for running tests
This commit is contained in:
parent
c773e2e828
commit
b2715bb56d
24
magefile.go
24
magefile.go
|
|
@ -55,7 +55,6 @@ var (
|
||||||
Version = "unstable" // This holds the built version, unstable by default, when building from a tag or release branch, their name
|
Version = "unstable" // This holds the built version, unstable by default, when building from a tag or release branch, their name
|
||||||
BinLocation = ""
|
BinLocation = ""
|
||||||
PkgVersion = "unstable"
|
PkgVersion = "unstable"
|
||||||
ApiPackages = []string{}
|
|
||||||
|
|
||||||
// Aliases are mage aliases of targets
|
// Aliases are mage aliases of targets
|
||||||
Aliases = map[string]interface{}{
|
Aliases = map[string]interface{}{
|
||||||
|
|
@ -166,19 +165,6 @@ func setExecutable() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setApiPackages() {
|
|
||||||
pkgs, err := runCmdWithOutput("go", "list", "all")
|
|
||||||
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/webtests") {
|
|
||||||
ApiPackages = append(ApiPackages, p)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Some variables can always get initialized, so we do just that.
|
// Some variables can always get initialized, so we do just that.
|
||||||
func init() {
|
func init() {
|
||||||
setExecutable()
|
setExecutable()
|
||||||
|
|
@ -355,10 +341,8 @@ type Test mg.Namespace
|
||||||
// Feature runs the feature tests
|
// Feature runs the feature tests
|
||||||
func (Test) Feature() error {
|
func (Test) Feature() error {
|
||||||
mg.Deps(initVars)
|
mg.Deps(initVars)
|
||||||
setApiPackages()
|
|
||||||
// We run everything sequentially and not in parallel to prevent issues with real test databases
|
// We run everything sequentially and not in parallel to prevent issues with real test databases
|
||||||
args := append([]string{"test", goDetectVerboseFlag(), "-p", "1", "-coverprofile", "cover.out", "-timeout", "45m"}, ApiPackages...)
|
return runAndStreamOutput("go", "test", goDetectVerboseFlag(), "-p", "1", "-coverprofile", "cover.out", "-timeout", "45m", "-short", "./...")
|
||||||
return runAndStreamOutput("go", args...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Coverage runs the tests and builds the coverage html file from coverage output
|
// Coverage runs the tests and builds the coverage html file from coverage output
|
||||||
|
|
@ -372,16 +356,14 @@ func (Test) Coverage() error {
|
||||||
func (Test) Web() error {
|
func (Test) Web() error {
|
||||||
mg.Deps(initVars)
|
mg.Deps(initVars)
|
||||||
// We run everything sequentially and not in parallel to prevent issues with real test databases
|
// We run everything sequentially and not in parallel to prevent issues with real test databases
|
||||||
args := []string{"test", goDetectVerboseFlag(), "-p", "1", "-timeout", "45m", PACKAGE + "/pkg/webtests"}
|
args := []string{"test", goDetectVerboseFlag(), "-p", "1", "-timeout", "45m", "./pkg/webtests"}
|
||||||
return runAndStreamOutput("go", args...)
|
return runAndStreamOutput("go", args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Test) Filter(filter string) error {
|
func (Test) Filter(filter string) error {
|
||||||
mg.Deps(initVars)
|
mg.Deps(initVars)
|
||||||
setApiPackages()
|
|
||||||
// We run everything sequentially and not in parallel to prevent issues with real test databases
|
// We run everything sequentially and not in parallel to prevent issues with real test databases
|
||||||
args := append([]string{"test", goDetectVerboseFlag(), "-p", "1", "-timeout", "45m", "-run", filter}, ApiPackages...)
|
return runAndStreamOutput("go", "test", goDetectVerboseFlag(), "-p", "1", "-timeout", "45m", "-run", filter, "-short", "./...")
|
||||||
return runAndStreamOutput("go", args...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Test) All() {
|
func (Test) All() {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
// Vikunja is a to-do list application to facilitate your life.
|
||||||
|
// Copyright 2018-present Vikunja and contributors. All rights reserved.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package webtests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
flag.Parse()
|
||||||
|
if testing.Short() {
|
||||||
|
println("-short requested, skipping long-running web tests")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
os.Exit(m.Run())
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue