MCPcopy Index your code
hub / github.com/github/github-mcp-server / Test_SearchUsers

Function Test_SearchUsers

pkg/github/search_test.go:512–696  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

510}
511
512func Test_SearchUsers(t *testing.T) {
513 // Verify tool definition once
514 serverTool := SearchUsers(translations.NullTranslationHelper)
515 tool := serverTool.Tool
516 require.NoError(t, toolsnaps.Test(tool.Name, tool))
517
518 assert.Equal(t, "search_users", tool.Name)
519 assert.NotEmpty(t, tool.Description)
520
521 schema, ok := tool.InputSchema.(*jsonschema.Schema)
522 require.True(t, ok, "InputSchema should be *jsonschema.Schema")
523 assert.Contains(t, schema.Properties, "query")
524 assert.Contains(t, schema.Properties, "sort")
525 assert.Contains(t, schema.Properties, "order")
526 assert.Contains(t, schema.Properties, "perPage")
527 assert.Contains(t, schema.Properties, "page")
528 assert.ElementsMatch(t, schema.Required, []string{"query"})
529
530 // Setup mock search results
531 mockSearchResult := &github.UsersSearchResult{
532 Total: github.Ptr(2),
533 IncompleteResults: github.Ptr(false),
534 Users: []*github.User{
535 {
536 Login: github.Ptr("user1"),
537 ID: github.Ptr(int64(1001)),
538 HTMLURL: github.Ptr("https://github.com/user1"),
539 AvatarURL: github.Ptr("https://avatars.githubusercontent.com/u/1001"),
540 },
541 {
542 Login: github.Ptr("user2"),
543 ID: github.Ptr(int64(1002)),
544 HTMLURL: github.Ptr("https://github.com/user2"),
545 AvatarURL: github.Ptr("https://avatars.githubusercontent.com/u/1002"),
546 Type: github.Ptr("User"),
547 },
548 },
549 }
550
551 tests := []struct {
552 name string
553 mockedClient *http.Client
554 requestArgs map[string]any
555 expectError bool
556 expectedResult *github.UsersSearchResult
557 expectedErrMsg string
558 }{
559 {
560 name: "successful users search with all parameters",
561 mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
562 GetSearchUsers: expectQueryParams(t, map[string]string{
563 "q": "type:user location:finland language:go",
564 "sort": "followers",
565 "order": "desc",
566 "page": "1",
567 "per_page": "30",
568 }).andThen(
569 mockResponse(t, http.StatusOK, mockSearchResult),

Callers

nothing calls this directly

Calls 14

TestFunction · 0.92
SearchUsersFunction · 0.85
expectQueryParamsFunction · 0.85
mockResponseFunction · 0.85
mustNewGHClientFunction · 0.85
createMCPRequestFunction · 0.85
ContextWithDepsFunction · 0.85
getErrorResultFunction · 0.85
getTextResultFunction · 0.85
andThenMethod · 0.80
WriteHeaderMethod · 0.80

Tested by

no test coverage detected