internal/jsonrpc2_v2,mcp: remove unneeded dependencies
Remove dependencies on the eventtest and testenv packages from jsonrpc2_v2 and mcp packages, in preparation for forking. Change-Id: Id0efb0c3187629f6fb1822cc853ec52acea41b0d Reviewed-on: https://go-review.googlesource.com/c/tools/+/682696 Reviewed-by: Jonathan Amsterdam <jba@google.com> Auto-Submit: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
0160cdefa0
commit
8bc9a9a9f5
3 changed files with 22 additions and 13 deletions
|
|
@ -12,9 +12,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"golang.org/x/tools/internal/event/export/eventtest"
|
|
||||||
"github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2"
|
"github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2"
|
||||||
"golang.org/x/tools/internal/stack/stacktest"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var callTests = []invoker{
|
var callTests = []invoker{
|
||||||
|
|
@ -130,8 +128,7 @@ func TestConnectionHeader(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testConnection(t *testing.T, framer jsonrpc2.Framer) {
|
func testConnection(t *testing.T, framer jsonrpc2.Framer) {
|
||||||
stacktest.NoLeak(t)
|
ctx := context.Background()
|
||||||
ctx := eventtest.NewContext(context.Background(), t)
|
|
||||||
listener, err := jsonrpc2.NetPipeListener(ctx)
|
listener, err := jsonrpc2.NetPipeListener(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
@ -147,7 +144,6 @@ func testConnection(t *testing.T, framer jsonrpc2.Framer) {
|
||||||
client, err := jsonrpc2.Dial(ctx,
|
client, err := jsonrpc2.Dial(ctx,
|
||||||
listener.Dialer(), binder{framer, func(h *handler) {
|
listener.Dialer(), binder{framer, func(h *handler) {
|
||||||
defer h.conn.Close()
|
defer h.conn.Close()
|
||||||
ctx := eventtest.NewContext(ctx, t)
|
|
||||||
test.Invoke(t, ctx, h)
|
test.Invoke(t, ctx, h)
|
||||||
if call, ok := test.(*call); ok {
|
if call, ok := test.(*call); ok {
|
||||||
// also run all simple call tests in echo mode
|
// also run all simple call tests in echo mode
|
||||||
|
|
|
||||||
|
|
@ -8,18 +8,26 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2"
|
"github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2"
|
||||||
"golang.org/x/tools/internal/stack/stacktest"
|
|
||||||
"golang.org/x/tools/internal/testenv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// needsLocalhostNet skips t if networking does not work for ports opened
|
||||||
|
// with "localhost".
|
||||||
|
// forked from golang.org/x/tools/internal/testenv.
|
||||||
|
func needsLocalhostNet(t testing.TB) {
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "js", "wasip1":
|
||||||
|
t.Skipf(`Listening on "localhost" fails on %s; see https://go.dev/issue/59718`, runtime.GOOS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIdleTimeout(t *testing.T) {
|
func TestIdleTimeout(t *testing.T) {
|
||||||
testenv.NeedsLocalhostNet(t)
|
needsLocalhostNet(t)
|
||||||
stacktest.NoLeak(t)
|
|
||||||
|
|
||||||
// Use a panicking time.AfterFunc instead of context.WithTimeout so that we
|
// Use a panicking time.AfterFunc instead of context.WithTimeout so that we
|
||||||
// get a goroutine dump on failure. We expect the test to take on the order of
|
// get a goroutine dump on failure. We expect the test to take on the order of
|
||||||
|
|
@ -158,7 +166,6 @@ func (fakeHandler) Handle(ctx context.Context, req *jsonrpc2.Request) (any, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServe(t *testing.T) {
|
func TestServe(t *testing.T) {
|
||||||
stacktest.NoLeak(t)
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
|
@ -166,7 +173,7 @@ func TestServe(t *testing.T) {
|
||||||
factory func(context.Context, testing.TB) (jsonrpc2.Listener, error)
|
factory func(context.Context, testing.TB) (jsonrpc2.Listener, error)
|
||||||
}{
|
}{
|
||||||
{"tcp", func(ctx context.Context, t testing.TB) (jsonrpc2.Listener, error) {
|
{"tcp", func(ctx context.Context, t testing.TB) (jsonrpc2.Listener, error) {
|
||||||
testenv.NeedsLocalhostNet(t)
|
needsLocalhostNet(t)
|
||||||
return jsonrpc2.NetListener(ctx, "tcp", "localhost:0", jsonrpc2.NetListenOptions{})
|
return jsonrpc2.NetListener(ctx, "tcp", "localhost:0", jsonrpc2.NetListenOptions{})
|
||||||
}},
|
}},
|
||||||
{"pipe", func(ctx context.Context, t testing.TB) (jsonrpc2.Listener, error) {
|
{"pipe", func(ctx context.Context, t testing.TB) (jsonrpc2.Listener, error) {
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,11 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||||
"golang.org/x/tools/internal/testenv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const runAsServer = "_MCP_RUN_AS_SERVER"
|
const runAsServer = "_MCP_RUN_AS_SERVER"
|
||||||
|
|
@ -39,7 +39,13 @@ func runServer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCmdTransport(t *testing.T) {
|
func TestCmdTransport(t *testing.T) {
|
||||||
testenv.NeedsExec(t)
|
// Conservatively, limit to major OS where we know that os.Exec is
|
||||||
|
// supported.
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "darwin", "linux", "windows":
|
||||||
|
default:
|
||||||
|
t.Skip("unsupported OS")
|
||||||
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue