packer/rpc: Return proper nil artifact if nil is returned
This commit is contained in:
parent
cd3523fd4f
commit
9bb24e6d90
|
@ -84,7 +84,12 @@ func (b *builder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := rpc.Dial("tcp", <-artifactAddress)
|
address := <-artifactAddress
|
||||||
|
if address == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := rpc.Dial("tcp", address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -127,12 +132,16 @@ func (b *BuilderServer) Run(args *BuilderRunArgs, reply *interface{}) error {
|
||||||
hook := Hook(client)
|
hook := Hook(client)
|
||||||
ui := &Ui{client}
|
ui := &Ui{client}
|
||||||
artifact := b.builder.Run(ui, hook)
|
artifact := b.builder.Run(ui, hook)
|
||||||
|
responseAddress := ""
|
||||||
|
|
||||||
// Wrap the artifact
|
if artifact != nil {
|
||||||
server := rpc.NewServer()
|
// Wrap the artifact
|
||||||
RegisterArtifact(server, artifact)
|
server := rpc.NewServer()
|
||||||
|
RegisterArtifact(server, artifact)
|
||||||
|
responseAddress = serveSingleConn(server)
|
||||||
|
}
|
||||||
|
|
||||||
responseWriter.Encode(&BuilderRunResponse{serveSingleConn(server)})
|
responseWriter.Encode(&BuilderRunResponse{responseAddress})
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -16,6 +16,8 @@ type testBuilder struct {
|
||||||
runHook packer.Hook
|
runHook packer.Hook
|
||||||
runUi packer.Ui
|
runUi packer.Ui
|
||||||
cancelCalled bool
|
cancelCalled bool
|
||||||
|
|
||||||
|
nilRunResult bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *testBuilder) Prepare(config interface{}) error {
|
func (b *testBuilder) Prepare(config interface{}) error {
|
||||||
|
@ -28,7 +30,12 @@ func (b *testBuilder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact {
|
||||||
b.runCalled = true
|
b.runCalled = true
|
||||||
b.runHook = hook
|
b.runHook = hook
|
||||||
b.runUi = ui
|
b.runUi = ui
|
||||||
return testBuilderArtifact
|
|
||||||
|
if !b.nilRunResult {
|
||||||
|
return testBuilderArtifact
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *testBuilder) Cancel() {
|
func (b *testBuilder) Cancel() {
|
||||||
|
@ -74,6 +81,11 @@ func TestBuilderRPC(t *testing.T) {
|
||||||
assert.Equal(artifact.Id(), testBuilderArtifact.Id(), "should have artifact Id")
|
assert.Equal(artifact.Id(), testBuilderArtifact.Id(), "should have artifact Id")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test run with nil result
|
||||||
|
b.nilRunResult = true
|
||||||
|
artifact = bClient.Run(ui, hook)
|
||||||
|
assert.Nil(artifact, "should be 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")
|
||||||
|
|
Loading…
Reference in New Issue