Skip to content

Commit 2d375f3

Browse files
authored
Fix/test exec binary (#22)
* fix: correct paths * fix: remove pre-release
1 parent 91764f9 commit 2d375f3

File tree

3 files changed

+64
-18
lines changed

3 files changed

+64
-18
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ jobs:
7676
generate_release_notes: true
7777
token: ${{ secrets.GITHUB_TOKEN }}
7878
files: ./dist/*
79-
prerelease: true
79+
prerelease: false

internal/web/web.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,7 @@ type Web struct {
6565

6666
// New returns an initialised instance of Web struct
6767
func New(ctx context.Context, conf *WebConfig) *Web {
68-
l := launcher.New()
69-
70-
browserExecPath, found := conf.CustomChromeExecutable, false
71-
// try default chrome location if custom location is not specified
72-
if browserExecPath == "" {
73-
if browserExecPath, found = launcher.LookPath(); browserExecPath != "" && found {
74-
l.Bin(browserExecPath)
75-
}
76-
}
77-
78-
// common set up
79-
l.Devtools(false).
80-
UserDataDir(conf.datadir).
81-
Headless(conf.headless).
82-
NoSandbox(conf.noSandbox).
83-
Leakless(conf.leakless)
68+
l := BuildLauncher(ctx, conf)
8469

8570
url := l.MustLaunch()
8671

@@ -98,6 +83,26 @@ func New(ctx context.Context, conf *WebConfig) *Web {
9883
return web
9984
}
10085

86+
func BuildLauncher(ctx context.Context, conf *WebConfig) *launcher.Launcher {
87+
l := launcher.New()
88+
89+
if conf.CustomChromeExecutable != "" {
90+
l.Bin(conf.CustomChromeExecutable)
91+
}
92+
// try default locations if custom location is not specified and default location exists
93+
if defaultExecPath, found := launcher.LookPath(); conf.CustomChromeExecutable == "" && defaultExecPath != "" && found {
94+
l.Bin(defaultExecPath)
95+
}
96+
97+
// common set up
98+
l.Devtools(false).
99+
UserDataDir(conf.datadir).
100+
Headless(conf.headless).
101+
NoSandbox(conf.noSandbox).
102+
Leakless(conf.leakless)
103+
return l
104+
}
105+
101106
func (web *Web) WithConfig(conf *WebConfig) *Web {
102107
web.conf = conf
103108
return web
@@ -217,7 +222,7 @@ func (web *Web) GetSSOCredentials(conf credentialexchange.CredentialConfig) (str
217222
}
218223

219224
func (web *Web) MustClose() {
220-
// swallows errors here - until a structured logger
225+
// swallows errors here - until a structured logger
221226
_ = web.browser.Close()
222227
utils.Sleep(0.5)
223228
// remove process just in case

internal/web/web_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,44 @@ func Test_WebUI_with_timeout_ssoLogin(t *testing.T) {
217217
t.Errorf("incorrect error returned\n expected: %s, got: %s", web.ErrTimedOut, err)
218218
}
219219
}
220+
221+
func Test_Web_BuildLauncher(t *testing.T) {
222+
ttests := map[string]struct {
223+
customExe string
224+
wantBin string
225+
}{
226+
"with custom executable": {
227+
customExe: "/fooo",
228+
wantBin: "/fooo",
229+
},
230+
"without custom": {
231+
customExe: "/path/to/another",
232+
wantBin: "/path/to/another",
233+
},
234+
}
235+
for name, tt := range ttests {
236+
t.Run(name, func(t *testing.T) {
237+
got := web.BuildLauncher(context.TODO(), &web.WebConfig{CustomChromeExecutable: tt.customExe})
238+
239+
bin := got.Get("rod-bin")
240+
if len(bin) < 1 && tt.wantBin != "" {
241+
t.Fatal("got no custom binary paths")
242+
}
243+
if bin != tt.wantBin {
244+
t.Fatalf("got %v, want %v", bin, tt.wantBin)
245+
}
246+
})
247+
}
248+
249+
t.Run("default browser is returned when no custom binary specified", func(t *testing.T) {
250+
// for people running this locally without a default chrome/chromium installed this will potentially fail
251+
//
252+
// run the tests in the `eirctl run unit:test:run`
253+
//
254+
got := web.BuildLauncher(context.TODO(), &web.WebConfig{CustomChromeExecutable: ""})
255+
bin := got.Get("rod-bin")
256+
if len(bin) < 1 {
257+
t.Fatal("got no binary paths")
258+
}
259+
})
260+
}

0 commit comments

Comments
 (0)