Skip to content

feat: Create provisioner abstraction #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 8, 2022
Merged
Prev Previous commit
Next Next commit
Add linguist-generated and closed pipe test
  • Loading branch information
kylecarbs committed Jan 7, 2022
commit 59992f197f8aec75b459aca97084db4958b3fbd2
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Generated files
provisionersdk/proto/*.go
provisionersdk/proto/*.go linguist-generated=true
4 changes: 4 additions & 0 deletions provisionersdk/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func Serve(ctx context.Context, server proto.DRPCProvisionerServer, options *Ser
return nil
}
if errors.Is(err, io.ErrClosedPipe) {
// This may occur if the transport on either end is
// closed before the context. It's fine to return
// nil here, since the server has nothing to
// communicate with.
return nil
}
return xerrors.Errorf("serve transport: %w", err)
Expand Down
10 changes: 10 additions & 0 deletions provisionersdk/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,14 @@ func TestProvisionerSDK(t *testing.T) {
_, err := api.Parse(context.Background(), &proto.Parse_Request{})
require.Equal(t, drpcerr.Unimplemented, int(drpcerr.Code(err)))
})
t.Run("ServeClosedPipe", func(t *testing.T) {
client, server := provisionersdk.TransportPipe()
_ = client.Close()
_ = server.Close()

err := provisionersdk.Serve(context.Background(), &proto.DRPCProvisionerUnimplementedServer{}, &provisionersdk.ServeOptions{
Transport: server,
})
require.NoError(t, err)
})
}