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

Function Test_SearchOrgs

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

Source from the content-addressed store, hash-verified

696}
697
698func Test_SearchOrgs(t *testing.T) {
699 // Verify tool definition once
700 serverTool := SearchOrgs(translations.NullTranslationHelper)
701 tool := serverTool.Tool
702
703 require.NoError(t, toolsnaps.Test(tool.Name, tool))
704
705 assert.Equal(t, "search_orgs", tool.Name)
706 assert.NotEmpty(t, tool.Description)
707
708 schema, ok := tool.InputSchema.(*jsonschema.Schema)
709 require.True(t, ok, "InputSchema should be *jsonschema.Schema")
710 assert.Contains(t, schema.Properties, "query")
711 assert.Contains(t, schema.Properties, "sort")
712 assert.Contains(t, schema.Properties, "order")
713 assert.Contains(t, schema.Properties, "perPage")
714 assert.Contains(t, schema.Properties, "page")
715 assert.ElementsMatch(t, schema.Required, []string{"query"})
716
717 // Setup mock search results
718 mockSearchResult := &github.UsersSearchResult{
719 Total: github.Ptr(int(2)),
720 IncompleteResults: github.Ptr(false),
721 Users: []*github.User{
722 {
723 Login: github.Ptr("org-1"),
724 ID: github.Ptr(int64(111)),
725 HTMLURL: github.Ptr("https://github.com/org-1"),
726 AvatarURL: github.Ptr("https://avatars.githubusercontent.com/u/111?v=4"),
727 },
728 {
729 Login: github.Ptr("org-2"),
730 ID: github.Ptr(int64(222)),
731 HTMLURL: github.Ptr("https://github.com/org-2"),
732 AvatarURL: github.Ptr("https://avatars.githubusercontent.com/u/222?v=4"),
733 },
734 },
735 }
736
737 tests := []struct {
738 name string
739 mockedClient *http.Client
740 requestArgs map[string]any
741 expectError bool
742 expectedResult *github.UsersSearchResult
743 expectedErrMsg string
744 }{
745 {
746 name: "successful org search",
747 mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
748 GetSearchUsers: expectQueryParams(t, map[string]string{
749 "q": "type:org github",
750 "page": "1",
751 "per_page": "30",
752 }).andThen(
753 mockResponse(t, http.StatusOK, mockSearchResult),
754 ),
755 }),

Callers

nothing calls this directly

Calls 14

TestFunction · 0.92
SearchOrgsFunction · 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