packer-cn/packer/rpc/hook_test.go

39 lines
707 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
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
2013-05-11 12:51:49 -04:00
)
func TestHook_Implements(t *testing.T) {
var _ packersdk.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 := &packersdk.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
}
}