| // Copyright 2020 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| "golang.org/x/tools/internal/jsonrpc2" |
| func fakeHandler(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2.Request) error { |
| return reply(ctx, &msg{"pong"}, nil) |
| func TestTestServer(t *testing.T) { |
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| server := jsonrpc2.HandlerServer(fakeHandler) |
| tcpTS := NewTCPServer(ctx, server) |
| pipeTS := NewPipeServer(ctx, server) |
| for _, test := range tests { |
| t.Run(test.name, func(t *testing.T) { |
| conn := test.connector.Connect(ctx) |
| conn.Go(ctx, jsonrpc2.MethodNotFound) |
| if _, err := conn.Call(ctx, "ping", &msg{"ping"}, &got); err != nil { |
| if want := "pong"; got.Msg != want { |
| t.Errorf("conn.Call(...): returned %q, want %q", got, want) |