packer-cn/packer/rpc/hook_test.go

39 lines
673 B
Go
Raw Normal View History

2013-05-11 12:51:49 -04:00
package rpc
import (
"context"
2013-05-11 12:51:49 -04:00
"testing"
2018-01-22 20:21:10 -05:00
"github.com/hashicorp/packer/packer"
2013-05-11 12:51:49 -04:00
)
func TestHook_Implements(t *testing.T) {
2013-10-16 23:04:57 -04:00
var _ packer.Hook = new(hook)
2013-05-11 12:51:49 -04:00
}
2013-08-31 02:10:16 -04:00
func TestHook_cancelWhileRun(t *testing.T) {
topCtx, cancelTopCtx := context.WithCancel(context.Background())
2013-08-31 02:10:16 -04:00
h := &packer.MockHook{
RunFunc: func(ctx context.Context) error {
cancelTopCtx()
<-ctx.Done()
return ctx.Err()
2013-08-31 02:10:16 -04:00
},
}
// Serve
2013-12-10 14:50:30 -05:00
client, server := testClientServer(t)
defer client.Close()
defer server.Close()
server.RegisterHook(h)
hClient := client.Hook()
2013-08-31 02:10:16 -04:00
// Start the run
err := hClient.Run(topCtx, "foo", nil, nil, nil)
2013-08-31 02:10:16 -04:00
if err == nil {
t.Fatal("should have errored")
2013-08-31 02:10:16 -04:00
}
}