2013-05-11 12:51:49 -04:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"cgl.tideland.biz/asserts"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
"net/rpc"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHookRPC(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
// Create the UI to test
|
2013-08-30 20:03:55 -04:00
|
|
|
h := new(packer.MockHook)
|
2013-05-11 12:51:49 -04:00
|
|
|
|
|
|
|
// Serve
|
|
|
|
server := rpc.NewServer()
|
|
|
|
RegisterHook(server, h)
|
|
|
|
address := serveSingleConn(server)
|
|
|
|
|
|
|
|
// Create the client over RPC and run some methods to verify it works
|
|
|
|
client, err := rpc.Dial("tcp", address)
|
|
|
|
assert.Nil(err, "should be able to connect")
|
|
|
|
|
|
|
|
hClient := Hook(client)
|
|
|
|
|
|
|
|
// Test Run
|
|
|
|
ui := &testUi{}
|
2013-05-12 20:30:30 -04:00
|
|
|
hClient.Run("foo", ui, nil, 42)
|
2013-08-30 20:03:55 -04:00
|
|
|
assert.True(h.RunCalled, "run should be called")
|
2013-08-31 02:03:43 -04:00
|
|
|
|
|
|
|
// Test Cancel
|
|
|
|
hClient.Cancel()
|
|
|
|
assert.True(h.CancelCalled, "cancel should be called")
|
2013-05-11 12:51:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestHook_Implements(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
var r packer.Hook
|
|
|
|
h := &hook{nil}
|
|
|
|
|
|
|
|
assert.Implementor(h, &r, "should be a Hook")
|
|
|
|
}
|