Skip to content

Commit

Permalink
Add ErrChromeNotFoundAtPath
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Dec 15, 2023
1 parent cafdaf0 commit 8f9fddb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
11 changes: 8 additions & 3 deletions chromium/browser_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,13 @@ func (b *BrowserType) allocate(
return common.NewLocalBrowserProcess(bProcCtx, path, args, dataDir, bProcCtxCancel, logger) //nolint: wrapcheck
}

// ErrChromeNotInstalled is returned when the Chrome executable is not found.
var ErrChromeNotInstalled = errors.New("neither chrome nor chromium is installed on this system")
var (
// ErrChromeNotInstalled is returned when the Chrome executable is not found.
ErrChromeNotInstalled = errors.New("neither chrome nor chromium is installed on this system")

// ErrChromeNotFoundAtPath is returned when the Chrome executable is not found at the given path.
ErrChromeNotFoundAtPath = errors.New("neither chrome nor chromium found on the path")
)

// executablePath returns the path where the extension expects to find the browser executable.
func executablePath(
Expand All @@ -261,7 +266,7 @@ func executablePath(
if _, err := lookPath(path); err == nil {
return path, nil
}
return "", ErrChromeNotInstalled
return "", fmt.Errorf("%w: %s", ErrChromeNotFoundAtPath, path)
}

// find the browser executable in the default paths below
Expand Down
18 changes: 9 additions & 9 deletions chromium/browser_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ func TestExecutablePath(t *testing.T) {
userProfile env.LookupFunc // user profile folder lookup

wantPath string
wantErr bool
wantErr error
}{
"without_chromium": {
userProvidedPath: "",
lookPath: fileNotExists,
userProfile: env.EmptyLookup,
wantPath: "",
wantErr: true,
wantErr: ErrChromeNotInstalled,
},
"with_chromium": {
userProvidedPath: "",
Expand All @@ -193,14 +193,14 @@ func TestExecutablePath(t *testing.T) {
},
userProfile: env.EmptyLookup,
wantPath: chromiumExecutable,
wantErr: false,
wantErr: nil,
},
"without_chromium_in_user_path": {
userProvidedPath: userProvidedPath,
lookPath: fileNotExists,
userProfile: env.EmptyLookup,
wantPath: "",
wantErr: true,
wantErr: ErrChromeNotFoundAtPath,
},
"with_chromium_in_user_path": {
userProvidedPath: userProvidedPath,
Expand All @@ -212,14 +212,14 @@ func TestExecutablePath(t *testing.T) {
},
userProfile: env.EmptyLookup,
wantPath: userProvidedPath,
wantErr: false,
wantErr: nil,
},
"without_chromium_in_user_profile": {
userProvidedPath: "",
lookPath: fileNotExists,
userProfile: env.ConstLookup("USERPROFILE", `home`),
wantPath: "",
wantErr: true,
wantErr: ErrChromeNotInstalled,
},
"with_chromium_in_user_profile": {
userProvidedPath: "",
Expand All @@ -231,7 +231,7 @@ func TestExecutablePath(t *testing.T) {
},
userProfile: env.ConstLookup("USERPROFILE", `home`),
wantPath: filepath.Join("home", `AppData\Local\Google\Chrome\Application\chrome.exe`),
wantErr: false,
wantErr: nil,
},
}
for name, tt := range tests {
Expand All @@ -243,8 +243,8 @@ func TestExecutablePath(t *testing.T) {

assert.Equal(t, tt.wantPath, path)

if tt.wantErr {
assert.Error(t, err)
if tt.wantErr != nil {
assert.ErrorIs(t, err, tt.wantErr)
return
}
assert.NoError(t, err)
Expand Down

0 comments on commit 8f9fddb

Please sign in to comment.