From 0645af7a416f116c2c4e76e7ee1d3216a8bb0044 Mon Sep 17 00:00:00 2001 From: Matej Vasek Date: Wed, 22 Mar 2023 19:21:55 +0100 Subject: [PATCH] fix: pre-compile mock binaries instead of 'go run' (#1645) The 'go run' does internally compile and it prolongs perceived run-time. This may lead to timeout in some tests. Signed-off-by: Matej Vasek --- pkg/testing/testing.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/pkg/testing/testing.go b/pkg/testing/testing.go index f9a2eb30..4b82d3aa 100644 --- a/pkg/testing/testing.go +++ b/pkg/testing/testing.go @@ -165,24 +165,16 @@ func WithExecutable(t *testing.T, name, goSrc string) { t.Fatal(err) } - runnerScriptName := name if runtime.GOOS == "windows" { - runnerScriptName = runnerScriptName + ".bat" + name = name + ".exe" } - runnerScriptSrc := `#!/bin/sh -exec go run GO_SCRIPT_PATH $@; -` - if runtime.GOOS == "windows" { - runnerScriptSrc = `@echo off -go.exe run GO_SCRIPT_PATH %* -` - } + binaryPath := filepath.Join(binDir, name) - runnerScriptPath := filepath.Join(binDir, runnerScriptName) - runnerScriptSrc = strings.ReplaceAll(runnerScriptSrc, "GO_SCRIPT_PATH", goSrcPath) - err = os.WriteFile(runnerScriptPath, []byte(runnerScriptSrc), 0700) + cmd := exec.Command("go", "build", "-o="+binaryPath, goSrcPath) + o, err := cmd.CombinedOutput() if err != nil { + t.Log(string(o)) t.Fatal(err) } }