Skip to content

Commit 02fc77f

Browse files
committed
add unit test
1 parent 97844ce commit 02fc77f

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

internal/server/mcp_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
"strings"
2828
"testing"
2929

30+
"github.com/googleapis/genai-toolbox/internal/auth"
31+
"github.com/googleapis/genai-toolbox/internal/auth/generic"
3032
"github.com/googleapis/genai-toolbox/internal/log"
3133
"github.com/googleapis/genai-toolbox/internal/server/mcp/jsonrpc"
3234
"github.com/googleapis/genai-toolbox/internal/server/resources"
@@ -1184,3 +1186,62 @@ func TestSseManagerGetNonExistentSession(t *testing.T) {
11841186
t.Error("expected nil session for non-existent ID")
11851187
}
11861188
}
1189+
1190+
func TestPRMEndpoint(t *testing.T) {
1191+
authSvcMap := map[string]auth.AuthService{
1192+
"generic1": generic.AuthService{
1193+
Config: generic.Config{
1194+
Name: "generic1",
1195+
Type: generic.AuthServiceType,
1196+
McpEnabled: true,
1197+
AuthURL: "https://example.com/oauth",
1198+
ScopesRequired: []string{"read", "write"},
1199+
},
1200+
},
1201+
}
1202+
resourceManager := resources.NewResourceManager(nil, authSvcMap, nil, nil, nil, nil, nil)
1203+
1204+
testLogger, err := log.NewStdLogger(os.Stdout, os.Stderr, "info")
1205+
if err != nil {
1206+
t.Fatalf("unable to initialize logger: %s", err)
1207+
}
1208+
1209+
s := &Server{
1210+
logger: testLogger,
1211+
ResourceMgr: resourceManager,
1212+
toolboxUrl: "https://my-toolbox.example.com",
1213+
}
1214+
1215+
r, err := mcpRouter(s)
1216+
if err != nil {
1217+
t.Fatalf("unexpected error creating router: %v", err)
1218+
}
1219+
1220+
ts := httptest.NewServer(r)
1221+
defer ts.Close()
1222+
1223+
resp, body, err := runRequest(ts, http.MethodGet, "/.well-known/oauth-protected-resource", nil, nil)
1224+
if err != nil {
1225+
t.Fatalf("unexpected error during request: %s", err)
1226+
}
1227+
1228+
if resp.StatusCode != http.StatusOK {
1229+
t.Fatalf("expected status %d, got %d", http.StatusOK, resp.StatusCode)
1230+
}
1231+
1232+
var got map[string]any
1233+
if err := json.Unmarshal(body, &got); err != nil {
1234+
t.Fatalf("unexpected error unmarshalling body: %s", err)
1235+
}
1236+
1237+
want := map[string]any{
1238+
"resource": "https://my-toolbox.example.com",
1239+
"authorization_servers": []any{
1240+
"https://example.com/oauth",
1241+
},
1242+
}
1243+
1244+
if !reflect.DeepEqual(got, want) {
1245+
t.Errorf("unexpected PRM response: got %+v, want %+v", got, want)
1246+
}
1247+
}

0 commit comments

Comments
 (0)