2013-05-22 18:35:52 -04:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2013-10-16 23:04:57 -04:00
|
|
|
"reflect"
|
2013-05-22 18:35:52 -04:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestProvisionerRPC(t *testing.T) {
|
|
|
|
// Create the interface to test
|
2013-08-31 02:21:15 -04:00
|
|
|
p := new(packer.MockProvisioner)
|
2013-05-22 18:35:52 -04:00
|
|
|
|
|
|
|
// Start the server
|
2013-12-10 14:56:15 -05:00
|
|
|
client, server := testClientServer(t)
|
|
|
|
defer client.Close()
|
|
|
|
defer server.Close()
|
|
|
|
server.RegisterProvisioner(p)
|
|
|
|
pClient := client.Provisioner()
|
2013-05-22 18:35:52 -04:00
|
|
|
|
|
|
|
// Test Prepare
|
|
|
|
config := 42
|
2013-06-06 20:01:12 -04:00
|
|
|
pClient.Prepare(config)
|
2013-10-16 23:04:57 -04:00
|
|
|
if !p.PrepCalled {
|
|
|
|
t.Fatal("should be called")
|
|
|
|
}
|
2014-04-26 16:31:22 -04:00
|
|
|
expected := []interface{}{int64(42)}
|
|
|
|
if !reflect.DeepEqual(p.PrepConfigs, expected) {
|
2013-10-16 23:04:57 -04:00
|
|
|
t.Fatalf("bad: %#v", p.PrepConfigs)
|
|
|
|
}
|
2013-05-22 18:35:52 -04:00
|
|
|
|
|
|
|
// Test Provision
|
2013-06-06 20:01:12 -04:00
|
|
|
ui := &testUi{}
|
2013-08-31 02:21:15 -04:00
|
|
|
comm := &packer.MockCommunicator{}
|
2013-05-22 18:35:52 -04:00
|
|
|
pClient.Provision(ui, comm)
|
2013-10-16 23:04:57 -04:00
|
|
|
if !p.ProvCalled {
|
|
|
|
t.Fatal("should be called")
|
|
|
|
}
|
2013-05-22 18:35:52 -04:00
|
|
|
|
2013-08-31 02:21:15 -04:00
|
|
|
// Test Cancel
|
|
|
|
pClient.Cancel()
|
|
|
|
if !p.CancelCalled {
|
|
|
|
t.Fatal("cancel should be called")
|
|
|
|
}
|
2013-05-22 18:35:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestProvisioner_Implements(t *testing.T) {
|
2013-12-10 16:26:07 -05:00
|
|
|
var _ packer.Provisioner = new(provisioner)
|
2013-05-22 18:35:52 -04:00
|
|
|
}
|