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 <mvasek@redhat.com>
This commit is contained in:
Matej Vasek 2023-03-22 19:21:55 +01:00 committed by GitHub
parent 8d4db7546d
commit 0645af7a41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 13 deletions

View File

@ -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)
}
}