2013-05-11 12:51:49 -04:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
2019-03-22 09:50:33 -04:00
|
|
|
"context"
|
2013-05-11 12:51:49 -04:00
|
|
|
"testing"
|
2018-01-22 20:21:10 -05:00
|
|
|
|
2020-11-19 18:10:00 -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) {
|
2020-11-19 18:10:00 -05:00
|
|
|
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) {
|
2019-03-27 07:29:09 -04:00
|
|
|
topCtx, cancelTopCtx := context.WithCancel(context.Background())
|
2013-08-31 02:10:16 -04:00
|
|
|
|
2020-11-20 13:21:29 -05:00
|
|
|
h := &packersdk.MockHook{
|
2019-03-27 07:29:09 -04:00
|
|
|
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
|
2019-03-27 07:29:09 -04:00
|
|
|
err := hClient.Run(topCtx, "foo", nil, nil, nil)
|
2013-08-31 02:10:16 -04:00
|
|
|
|
2019-03-27 07:29:09 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have errored")
|
2013-08-31 02:10:16 -04:00
|
|
|
}
|
|
|
|
}
|