mirror of
https://github.com/sourcegraph/jsonrpc2.git
synced 2026-06-16 04:04:56 +02:00
Expose NoopHandler
This commit is contained in:
parent
c9c77b6bb9
commit
e8229febb0
5 changed files with 14 additions and 12 deletions
|
|
@ -22,7 +22,7 @@ func TestPickID(t *testing.T) {
|
|||
}
|
||||
})
|
||||
connA := jsonrpc2.NewConn(ctx, jsonrpc2.NewBufferedStream(a, jsonrpc2.VSCodeObjectCodec{}), handler)
|
||||
connB := jsonrpc2.NewConn(ctx, jsonrpc2.NewBufferedStream(b, jsonrpc2.VSCodeObjectCodec{}), noopHandler{})
|
||||
connB := jsonrpc2.NewConn(ctx, jsonrpc2.NewBufferedStream(b, jsonrpc2.VSCodeObjectCodec{}), jsonrpc2.NoopHandler{})
|
||||
defer connA.Close()
|
||||
defer connB.Close()
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ func TestStringID(t *testing.T) {
|
|||
}
|
||||
})
|
||||
connA := jsonrpc2.NewConn(ctx, jsonrpc2.NewBufferedStream(a, jsonrpc2.VSCodeObjectCodec{}), handler)
|
||||
connB := jsonrpc2.NewConn(ctx, jsonrpc2.NewBufferedStream(b, jsonrpc2.VSCodeObjectCodec{}), noopHandler{})
|
||||
connB := jsonrpc2.NewConn(ctx, jsonrpc2.NewBufferedStream(b, jsonrpc2.VSCodeObjectCodec{}), jsonrpc2.NoopHandler{})
|
||||
defer connA.Close()
|
||||
defer connB.Close()
|
||||
|
||||
|
|
@ -131,7 +131,7 @@ func TestExtraField(t *testing.T) {
|
|||
}
|
||||
})
|
||||
connA := jsonrpc2.NewConn(ctx, jsonrpc2.NewBufferedStream(a, jsonrpc2.VSCodeObjectCodec{}), handler)
|
||||
connB := jsonrpc2.NewConn(ctx, jsonrpc2.NewBufferedStream(b, jsonrpc2.VSCodeObjectCodec{}), noopHandler{})
|
||||
connB := jsonrpc2.NewConn(ctx, jsonrpc2.NewBufferedStream(b, jsonrpc2.VSCodeObjectCodec{}), jsonrpc2.NoopHandler{})
|
||||
defer connA.Close()
|
||||
defer connB.Close()
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ func TestPlainObjectCodec(t *testing.T) {
|
|||
connA := jsonrpc2.NewConn(
|
||||
context.Background(),
|
||||
jsonrpc2.NewBufferedStream(cA, jsonrpc2.PlainObjectCodec{}),
|
||||
noopHandler{},
|
||||
jsonrpc2.NoopHandler{},
|
||||
)
|
||||
defer connA.Close()
|
||||
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ func TestSetLogger(t *testing.T) {
|
|||
connA := jsonrpc2.NewConn(
|
||||
ctx,
|
||||
jsonrpc2.NewBufferedStream(a, jsonrpc2.VSCodeObjectCodec{}),
|
||||
noopHandler{},
|
||||
jsonrpc2.NoopHandler{},
|
||||
jsonrpc2.SetLogger(logger),
|
||||
)
|
||||
connB := jsonrpc2.NewConn(
|
||||
ctx,
|
||||
jsonrpc2.NewBufferedStream(b, jsonrpc2.VSCodeObjectCodec{}),
|
||||
noopHandler{},
|
||||
jsonrpc2.NoopHandler{},
|
||||
)
|
||||
defer connA.Close()
|
||||
defer connB.Close()
|
||||
|
|
|
|||
|
|
@ -303,6 +303,12 @@ type Handler interface {
|
|||
Handle(context.Context, *Conn, *Request)
|
||||
}
|
||||
|
||||
// NoopHandler is a Handler that does nothing. It is useful for
|
||||
// creating a Handler that can be used as a default handler. It is also
|
||||
// useful for testing.
|
||||
type NoopHandler struct {}
|
||||
func (NoopHandler) Handle(ctx context.Context, conn *Conn, req *Request) {}
|
||||
|
||||
// ID represents a JSON-RPC 2.0 request ID, which may be either a
|
||||
// string or number (or null, which is unsupported).
|
||||
type ID struct {
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@ func TestHandlerBlocking(t *testing.T) {
|
|||
wg.Done()
|
||||
})
|
||||
connA := jsonrpc2.NewConn(ctx, jsonrpc2.NewBufferedStream(a, jsonrpc2.VSCodeObjectCodec{}), handler)
|
||||
connB := jsonrpc2.NewConn(ctx, jsonrpc2.NewBufferedStream(b, jsonrpc2.VSCodeObjectCodec{}), noopHandler{})
|
||||
connB := jsonrpc2.NewConn(ctx, jsonrpc2.NewBufferedStream(b, jsonrpc2.VSCodeObjectCodec{}), jsonrpc2.NoopHandler{})
|
||||
defer connA.Close()
|
||||
defer connB.Close()
|
||||
|
||||
|
|
@ -287,10 +287,6 @@ func TestHandlerBlocking(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
type noopHandler struct{}
|
||||
|
||||
func (noopHandler) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) {}
|
||||
|
||||
type readWriteCloser struct {
|
||||
read, write func(p []byte) (n int, err error)
|
||||
}
|
||||
|
|
@ -348,7 +344,7 @@ func TestConn_DisconnectNotify_Close_async(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestConn_Close_waitingForResponse(t *testing.T) {
|
||||
c := jsonrpc2.NewConn(context.Background(), jsonrpc2.NewBufferedStream(&readWriteCloser{eof, eof}, jsonrpc2.VarintObjectCodec{}), noopHandler{})
|
||||
c := jsonrpc2.NewConn(context.Background(), jsonrpc2.NewBufferedStream(&readWriteCloser{eof, eof}, jsonrpc2.VarintObjectCodec{}), jsonrpc2.NoopHandler{})
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
if err := c.Call(context.Background(), "m", nil, nil); err != jsonrpc2.ErrClosed {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue