diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 226f37d..22ec08d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -76,4 +76,4 @@ jobs: generate_release_notes: true token: ${{ secrets.GITHUB_TOKEN }} files: ./dist/* - prerelease: true + prerelease: false diff --git a/internal/web/web.go b/internal/web/web.go index 35ac0f9..85946eb 100755 --- a/internal/web/web.go +++ b/internal/web/web.go @@ -65,22 +65,7 @@ type Web struct { // New returns an initialised instance of Web struct func New(ctx context.Context, conf *WebConfig) *Web { - l := launcher.New() - - browserExecPath, found := conf.CustomChromeExecutable, false - // try default chrome location if custom location is not specified - if browserExecPath == "" { - if browserExecPath, found = launcher.LookPath(); browserExecPath != "" && found { - l.Bin(browserExecPath) - } - } - - // common set up - l.Devtools(false). - UserDataDir(conf.datadir). - Headless(conf.headless). - NoSandbox(conf.noSandbox). - Leakless(conf.leakless) + l := BuildLauncher(ctx, conf) url := l.MustLaunch() @@ -98,6 +83,26 @@ func New(ctx context.Context, conf *WebConfig) *Web { return web } +func BuildLauncher(ctx context.Context, conf *WebConfig) *launcher.Launcher { + l := launcher.New() + + if conf.CustomChromeExecutable != "" { + l.Bin(conf.CustomChromeExecutable) + } + // try default locations if custom location is not specified and default location exists + if defaultExecPath, found := launcher.LookPath(); conf.CustomChromeExecutable == "" && defaultExecPath != "" && found { + l.Bin(defaultExecPath) + } + + // common set up + l.Devtools(false). + UserDataDir(conf.datadir). + Headless(conf.headless). + NoSandbox(conf.noSandbox). + Leakless(conf.leakless) + return l +} + func (web *Web) WithConfig(conf *WebConfig) *Web { web.conf = conf return web @@ -217,7 +222,7 @@ func (web *Web) GetSSOCredentials(conf credentialexchange.CredentialConfig) (str } func (web *Web) MustClose() { - // swallows errors here - until a structured logger + // swallows errors here - until a structured logger _ = web.browser.Close() utils.Sleep(0.5) // remove process just in case diff --git a/internal/web/web_test.go b/internal/web/web_test.go index 9384a03..2fc5b29 100644 --- a/internal/web/web_test.go +++ b/internal/web/web_test.go @@ -217,3 +217,44 @@ func Test_WebUI_with_timeout_ssoLogin(t *testing.T) { t.Errorf("incorrect error returned\n expected: %s, got: %s", web.ErrTimedOut, err) } } + +func Test_Web_BuildLauncher(t *testing.T) { + ttests := map[string]struct { + customExe string + wantBin string + }{ + "with custom executable": { + customExe: "/fooo", + wantBin: "/fooo", + }, + "without custom": { + customExe: "/path/to/another", + wantBin: "/path/to/another", + }, + } + for name, tt := range ttests { + t.Run(name, func(t *testing.T) { + got := web.BuildLauncher(context.TODO(), &web.WebConfig{CustomChromeExecutable: tt.customExe}) + + bin := got.Get("rod-bin") + if len(bin) < 1 && tt.wantBin != "" { + t.Fatal("got no custom binary paths") + } + if bin != tt.wantBin { + t.Fatalf("got %v, want %v", bin, tt.wantBin) + } + }) + } + + t.Run("default browser is returned when no custom binary specified", func(t *testing.T) { + // for people running this locally without a default chrome/chromium installed this will potentially fail + // + // run the tests in the `eirctl run unit:test:run` + // + got := web.BuildLauncher(context.TODO(), &web.WebConfig{CustomChromeExecutable: ""}) + bin := got.Get("rod-bin") + if len(bin) < 1 { + t.Fatal("got no binary paths") + } + }) +}