2021-09-15 05:51:22 +01:00
|
|
|
//go:build mage
|
2021-08-18 01:40:12 +01:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/magefile/mage/sh"
|
|
|
|
)
|
|
|
|
|
2021-09-15 00:25:05 +01:00
|
|
|
const (
|
2021-09-25 13:13:41 +01:00
|
|
|
binary = "canal"
|
2021-09-15 00:25:05 +01:00
|
|
|
)
|
|
|
|
|
2021-08-18 01:40:12 +01:00
|
|
|
var Default = Build
|
|
|
|
|
2021-09-15 00:25:05 +01:00
|
|
|
// Test run the go tests
|
2021-09-25 13:13:41 +01:00
|
|
|
// To enable verbose mode set CANAL_TEST_VERBOSE=1.
|
|
|
|
// To enable coverage mode set CANAL_TEST_COVER=1.
|
2021-09-15 00:25:05 +01:00
|
|
|
func Test() error {
|
|
|
|
goTest := sh.RunCmd("go", "test")
|
|
|
|
|
2021-09-18 01:03:09 +01:00
|
|
|
args := []string{"./..."}
|
2021-09-15 00:25:05 +01:00
|
|
|
|
2021-09-25 13:13:41 +01:00
|
|
|
if os.Getenv("CANAL_TEST_VERBOSE") == "1" {
|
2021-09-15 00:25:05 +01:00
|
|
|
args = append(args, "-v")
|
|
|
|
}
|
|
|
|
|
2021-09-25 13:13:41 +01:00
|
|
|
if os.Getenv("CANAL_TEST_COVER") == "1" {
|
2021-09-15 00:25:05 +01:00
|
|
|
args = append(args, "-cover")
|
|
|
|
}
|
|
|
|
|
|
|
|
return goTest(args...)
|
|
|
|
}
|
|
|
|
|
2021-09-15 10:09:48 +01:00
|
|
|
// Lint runs golangci-lint against the code.
|
|
|
|
func Lint() error {
|
|
|
|
return sh.RunV("golangci-lint", "run", "--color", "always")
|
|
|
|
}
|
|
|
|
|
2021-09-15 00:25:05 +01:00
|
|
|
// Build build the executable
|
|
|
|
func Build() error {
|
2021-09-25 13:13:41 +01:00
|
|
|
main := "./cmd/canal/main.go"
|
2021-09-18 01:03:09 +01:00
|
|
|
return sh.Run("go", "build", "-o", binary, main)
|
2021-09-15 00:25:05 +01:00
|
|
|
}
|
2021-09-14 20:58:54 +01:00
|
|
|
|
2021-08-18 01:40:12 +01:00
|
|
|
// Clean clean the workspace
|
|
|
|
func Clean() error {
|
2021-09-15 00:25:05 +01:00
|
|
|
if err := sh.Rm(binary); err != nil {
|
2021-09-14 20:58:54 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-18 01:40:12 +01:00
|
|
|
if err := sh.Run("go", "clean", "./..."); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
testDBDir := "./test/databases"
|
|
|
|
|
|
|
|
files, err := os.ReadDir(testDBDir)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range files {
|
|
|
|
filename := f.Name()
|
|
|
|
if strings.HasSuffix(filename, ".db") {
|
2021-09-15 00:25:05 +01:00
|
|
|
sh.Rm(testDBDir + "/" + filename)
|
2021-08-18 01:40:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|