Fix test coverage in docker containers

This commit is contained in:
Riccardo Biraghi
2018-04-20 17:34:37 +02:00
parent 818cbaca8d
commit d7633d8313
4 changed files with 58 additions and 42 deletions

View File

@@ -19,6 +19,7 @@ import (
"flag"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"testing"
@@ -27,8 +28,6 @@ import (
var test *bool
const filename = "/var/coverage/exitCode"
func init() {
test = flag.Bool("test", false, "Set to true when running tests for coverage")
log, _ = logger.NewLogger(os.Stdout, true, false, "test")
@@ -41,6 +40,14 @@ func TestSystem(t *testing.T) {
defer func() {
osExit = oldExit
}()
filename, ok := os.LookupEnv("EXIT_CODE_FILE")
if !ok {
filename = "/var/coverage/exitCode"
} else {
filename = filepath.Join("/var/coverage/", filename)
}
osExit = func(rc int) {
// Write the exit code to a file instead
log.Printf("Writing exit code %v to file %v", strconv.Itoa(rc), filename)