Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
ac0d0095
Commit
ac0d0095
authored
Nov 16, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16950 from swagiaal/handle-exec-not-found
Auto commit by PR queue bot
parents
5828836e
4d373b13
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
6 deletions
+22
-6
exec.go
pkg/util/exec/exec.go
+13
-6
exec_test.go
pkg/util/exec/exec_test.go
+9
-0
No files found.
pkg/util/exec/exec.go
View file @
ac0d0095
...
...
@@ -21,6 +21,9 @@ import (
"syscall"
)
// ErrExecutableNotFound is returned if the executable is not found.
var
ErrExecutableNotFound
=
osexec
.
ErrNotFound
// Interface is an interface that presents a subset of the os/exec API. Use this
// when you want to inject fakeable/mockable exec behavior.
type
Interface
interface
{
...
...
@@ -81,13 +84,17 @@ func (cmd *cmdWrapper) SetDir(dir string) {
func
(
cmd
*
cmdWrapper
)
CombinedOutput
()
([]
byte
,
error
)
{
out
,
err
:=
(
*
osexec
.
Cmd
)(
cmd
)
.
CombinedOutput
()
if
err
!=
nil
{
ee
,
ok
:=
err
.
(
*
osexec
.
ExitError
)
if
!
ok
{
return
out
,
err
if
ee
,
ok
:=
err
.
(
*
osexec
.
ExitError
);
ok
{
// Force a compile fail if exitErrorWrapper can't convert to ExitError.
var
x
ExitError
=
&
exitErrorWrapper
{
ee
}
return
out
,
x
}
if
ee
,
ok
:=
err
.
(
*
osexec
.
Error
);
ok
{
if
ee
.
Err
==
osexec
.
ErrNotFound
{
return
out
,
ErrExecutableNotFound
}
}
// Force a compile fail if exitErrorWrapper can't convert to ExitError.
var
x
ExitError
=
&
exitErrorWrapper
{
ee
}
return
out
,
x
return
out
,
err
}
return
out
,
nil
}
...
...
pkg/util/exec/exec_test.go
View file @
ac0d0095
...
...
@@ -92,3 +92,12 @@ func TestLookPath(t *testing.T) {
t
.
Errorf
(
"unexpected result for LookPath: got %s, expected %s"
,
sh
,
shExpected
)
}
}
func
TestExecutableNotFound
(
t
*
testing
.
T
)
{
exec
:=
New
()
cmd
:=
exec
.
Command
(
"fake_executable_name"
)
_
,
err
:=
cmd
.
CombinedOutput
()
if
err
!=
ErrExecutableNotFound
{
t
.
Errorf
(
"Expected error ErrExecutableNotFound but got %v"
,
err
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment