78 строки
1,3 КиБ
Go
78 строки
1,3 КиБ
Go
//go:build mage
|
|
// +build mage
|
|
|
|
package main
|
|
|
|
import (
|
|
// mage:import
|
|
. "magefile/docker"
|
|
)
|
|
|
|
var (
|
|
GolangVolume = "golang.upstream"
|
|
MyGoImageName = "my/go"
|
|
GOPATH = "/gopath"
|
|
GOCACHE = GOPATH + "/gocache"
|
|
GoPathMount = "-v " + GOPATH + ":" + GOPATH + ":rw"
|
|
GoPathEnv = "-e GOPATH=" + GOPATH
|
|
GoCacheEnv = "-e GOCACHE=" + GOCACHE
|
|
GolangMount = "-v " + GolangVolume + ":/usr/local/go:ro"
|
|
GoAll = GolangMount + ` \
|
|
` + GoPathMount + ` \
|
|
` + GoPathEnv + ` \
|
|
` + GoCacheEnv
|
|
|
|
tests_to_run = []string{}
|
|
)
|
|
|
|
func init() {
|
|
AppName = "schet"
|
|
ImageName = "my/go"
|
|
NetName = "none"
|
|
|
|
RunFn = run
|
|
}
|
|
|
|
func run() error {
|
|
err := BuildCMD()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return Bash(`./schet config.json statement.txt`)
|
|
}
|
|
|
|
func BuildCMD() error {
|
|
return Bash(`go build -o schet cmd/schet/main.go `)
|
|
}
|
|
|
|
func Test() {
|
|
runTests("./...", false)
|
|
}
|
|
func TestVerbose() {
|
|
runTests("./...", true)
|
|
}
|
|
|
|
func runTests(path string, verbose bool) error {
|
|
v := ""
|
|
if verbose {
|
|
v = "-v"
|
|
}
|
|
return Bash(`sudo docker run -ti --rm \
|
|
-h host \
|
|
--net=none \
|
|
-v /etc/localtime:/etc/localtime:ro \
|
|
\
|
|
` + GoAll + ` \
|
|
\
|
|
-v ${PWD}:/app \
|
|
\
|
|
-w /app \
|
|
-u 1000 \
|
|
\
|
|
--entrypoint=/bin/bash \
|
|
\
|
|
` + ImageName + " -c '" + ` \
|
|
go test ` + v + ` -gcflags=-l -count=1 ` + path + `
|
|
'`)
|
|
}
|