Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
d2023c69
Commit
d2023c69
authored
Jun 12, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: returning errors from builds works properly
parent
db8aeaba
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
5 deletions
+19
-5
packer/rpc/build.go
packer/rpc/build.go
+3
-3
packer/rpc/build_test.go
packer/rpc/build_test.go
+16
-2
No files found.
packer/rpc/build.go
View file @
d2023c69
...
@@ -57,12 +57,12 @@ func (b *build) Run(ui packer.Ui, cache packer.Cache) (packer.Artifact, error) {
...
@@ -57,12 +57,12 @@ func (b *build) Run(ui packer.Ui, cache packer.Cache) (packer.Artifact, error) {
var
reply
string
var
reply
string
if
err
:=
b
.
client
.
Call
(
"Build.Run"
,
args
,
&
reply
);
err
!=
nil
{
if
err
:=
b
.
client
.
Call
(
"Build.Run"
,
args
,
&
reply
);
err
!=
nil
{
panic
(
err
)
return
nil
,
err
}
}
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
reply
)
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
reply
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
return
nil
,
err
}
}
return
Artifact
(
client
),
nil
return
Artifact
(
client
),
nil
...
@@ -97,7 +97,7 @@ func (b *BuildServer) Run(args *BuildRunArgs, reply *string) error {
...
@@ -97,7 +97,7 @@ func (b *BuildServer) Run(args *BuildRunArgs, reply *string) error {
artifact
,
err
:=
b
.
build
.
Run
(
&
Ui
{
client
},
Cache
(
client
))
artifact
,
err
:=
b
.
build
.
Run
(
&
Ui
{
client
},
Cache
(
client
))
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
NewBasicError
(
err
)
}
}
// Wrap the artifact
// Wrap the artifact
...
...
packer/rpc/build_test.go
View file @
d2023c69
...
@@ -2,6 +2,7 @@ package rpc
...
@@ -2,6 +2,7 @@ package rpc
import
(
import
(
"cgl.tideland.biz/asserts"
"cgl.tideland.biz/asserts"
"errors"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"net/rpc"
"net/rpc"
"testing"
"testing"
...
@@ -17,6 +18,8 @@ type testBuild struct {
...
@@ -17,6 +18,8 @@ type testBuild struct {
runCache
packer
.
Cache
runCache
packer
.
Cache
runUi
packer
.
Ui
runUi
packer
.
Ui
cancelCalled
bool
cancelCalled
bool
errRunResult
bool
}
}
func
(
b
*
testBuild
)
Name
()
string
{
func
(
b
*
testBuild
)
Name
()
string
{
...
@@ -34,7 +37,12 @@ func (b *testBuild) Run(ui packer.Ui, cache packer.Cache) (packer.Artifact, erro
...
@@ -34,7 +37,12 @@ func (b *testBuild) Run(ui packer.Ui, cache packer.Cache) (packer.Artifact, erro
b
.
runCalled
=
true
b
.
runCalled
=
true
b
.
runCache
=
cache
b
.
runCache
=
cache
b
.
runUi
=
ui
b
.
runUi
=
ui
if
b
.
errRunResult
{
return
nil
,
errors
.
New
(
"foo"
)
}
else
{
return
testBuildArtifact
,
nil
return
testBuildArtifact
,
nil
}
}
}
func
(
b
*
testBuild
)
Cancel
()
{
func
(
b
*
testBuild
)
Cancel
()
{
...
@@ -69,8 +77,9 @@ func TestBuildRPC(t *testing.T) {
...
@@ -69,8 +77,9 @@ func TestBuildRPC(t *testing.T) {
// Test Run
// Test Run
cache
:=
new
(
testCache
)
cache
:=
new
(
testCache
)
ui
=
new
(
testUi
)
ui
=
new
(
testUi
)
bClient
.
Run
(
ui
,
cache
)
_
,
err
=
bClient
.
Run
(
ui
,
cache
)
assert
.
True
(
b
.
runCalled
,
"run should be called"
)
assert
.
True
(
b
.
runCalled
,
"run should be called"
)
assert
.
Nil
(
err
,
"should not error"
)
// Test the UI given to run, which should be fully functional
// Test the UI given to run, which should be fully functional
if
b
.
runCalled
{
if
b
.
runCalled
{
...
@@ -82,6 +91,11 @@ func TestBuildRPC(t *testing.T) {
...
@@ -82,6 +91,11 @@ func TestBuildRPC(t *testing.T) {
assert
.
Equal
(
ui
.
sayMessage
,
"format"
,
"message should be correct"
)
assert
.
Equal
(
ui
.
sayMessage
,
"format"
,
"message should be correct"
)
}
}
// Test run with an error
b
.
errRunResult
=
true
_
,
err
=
bClient
.
Run
(
ui
,
cache
)
assert
.
NotNil
(
err
,
"should not nil"
)
// Test Cancel
// Test Cancel
bClient
.
Cancel
()
bClient
.
Cancel
()
assert
.
True
(
b
.
cancelCalled
,
"cancel should be called"
)
assert
.
True
(
b
.
cancelCalled
,
"cancel should be called"
)
...
...
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