use runner.LookChromeNames in TestMain

It supports alternative names for Chrome such as chromium, as well as
extra names to look for like headless-shell.

Also swap the os.Getenv logic, so that we only do the exec.LookPath work
if the env var is unset.
This commit is contained in:
Daniel Martí 2019-02-21 13:53:05 +01:00
parent 5dc1e0f3af
commit 5ca52f3e1b

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"log" "log"
"os" "os"
"os/exec"
"path" "path"
"testing" "testing"
"time" "time"
@ -78,16 +77,9 @@ func TestMain(m *testing.M) {
// its worth noting that newer versions of chrome (64+) run much faster // its worth noting that newer versions of chrome (64+) run much faster
// than older ones -- same for headless_shell ... // than older ones -- same for headless_shell ...
execPath := runner.DefaultChromePath execPath := os.Getenv("CHROMEDP_TEST_RUNNER")
if testRunner := os.Getenv("CHROMEDP_TEST_RUNNER"); testRunner != "" { if execPath == "" {
execPath = testRunner execPath = runner.LookChromeNames("headless_shell")
} else {
// use headless_shell, if on path
var hsPath string
hsPath, err = exec.LookPath("headless_shell")
if err == nil {
execPath = hsPath
}
} }
cliOpts = append(cliOpts, runner.ExecPath(execPath)) cliOpts = append(cliOpts, runner.ExecPath(execPath))