Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ jobs:
generate_release_notes: true
token: ${{ secrets.GITHUB_TOKEN }}
files: ./dist/*
prerelease: true
prerelease: false
39 changes: 22 additions & 17 deletions internal/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions internal/web/web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
})
}