2013-05-22 15:35:52 -07:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
2019-03-19 18:11:19 +01:00
|
|
|
"context"
|
2013-10-16 17:04:57 -10:00
|
|
|
"reflect"
|
2013-05-22 15:35:52 -07:00
|
|
|
"testing"
|
2018-01-22 17:21:10 -08:00
|
|
|
|
|
|
|
"github.com/hashicorp/packer/packer"
|
2013-05-22 15:35:52 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestProvisionerRPC(t *testing.T) {
|
2019-03-27 12:29:09 +01:00
|
|
|
topCtx, topCtxCancel := context.WithCancel(context.Background())
|
|
|
|
|
2013-05-22 15:35:52 -07:00
|
|
|
// Create the interface to test
|
2013-08-30 23:21:15 -07:00
|
|
|
p := new(packer.MockProvisioner)
|
2019-03-27 12:29:09 +01:00
|
|
|
p.ProvFunc = func(ctx context.Context) error {
|
|
|
|
topCtxCancel()
|
|
|
|
<-ctx.Done()
|
|
|
|
return ctx.Err()
|
|
|
|
}
|
2013-05-22 15:35:52 -07:00
|
|
|
|
|
|
|
// Start the server
|
2013-12-10 11:56:15 -08:00
|
|
|
client, server := testClientServer(t)
|
|
|
|
defer client.Close()
|
|
|
|
defer server.Close()
|
|
|
|
server.RegisterProvisioner(p)
|
|
|
|
pClient := client.Provisioner()
|
2013-05-22 15:35:52 -07:00
|
|
|
// Test Prepare
|
|
|
|
config := 42
|
2013-06-06 17:01:12 -07:00
|
|
|
pClient.Prepare(config)
|
2013-10-16 17:04:57 -10:00
|
|
|
if !p.PrepCalled {
|
|
|
|
t.Fatal("should be called")
|
|
|
|
}
|
2014-04-26 13:31:22 -07:00
|
|
|
expected := []interface{}{int64(42)}
|
|
|
|
if !reflect.DeepEqual(p.PrepConfigs, expected) {
|
2013-10-16 17:04:57 -10:00
|
|
|
t.Fatalf("bad: %#v", p.PrepConfigs)
|
|
|
|
}
|
2013-05-22 15:35:52 -07:00
|
|
|
|
|
|
|
// Test Provision
|
2013-06-06 17:01:12 -07:00
|
|
|
ui := &testUi{}
|
2013-08-30 23:21:15 -07:00
|
|
|
comm := &packer.MockCommunicator{}
|
2019-12-12 10:59:44 -08:00
|
|
|
if err := pClient.Provision(topCtx, ui, comm, make(map[string]interface{})); err == nil {
|
2019-03-27 12:29:09 +01:00
|
|
|
t.Fatalf("Provison should have err")
|
2019-03-19 18:11:19 +01:00
|
|
|
}
|
2013-10-16 17:04:57 -10:00
|
|
|
if !p.ProvCalled {
|
|
|
|
t.Fatal("should be called")
|
|
|
|
}
|
2013-05-22 15:35:52 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProvisioner_Implements(t *testing.T) {
|
2013-12-10 13:26:07 -08:00
|
|
|
var _ packer.Provisioner = new(provisioner)
|
2013-05-22 15:35:52 -07:00
|
|
|
}
|