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

Function Test_SearchCode

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

Source from the content-addressed store, hash-verified

339}
340
341func Test_SearchCode(t *testing.T) {
342 // Verify tool definition once
343 serverTool := SearchCode(translations.NullTranslationHelper)
344 tool := serverTool.Tool
345 require.NoError(t, toolsnaps.Test(tool.Name, tool))
346
347 assert.Equal(t, "search_code", tool.Name)
348 assert.NotEmpty(t, tool.Description)
349
350 schema, ok := tool.InputSchema.(*jsonschema.Schema)
351 require.True(t, ok, "InputSchema should be *jsonschema.Schema")
352 assert.Contains(t, schema.Properties, "query")
353 assert.Contains(t, schema.Properties, "sort")
354 assert.Contains(t, schema.Properties, "order")
355 assert.Contains(t, schema.Properties, "perPage")
356 assert.Contains(t, schema.Properties, "page")
357 assert.ElementsMatch(t, schema.Required, []string{"query"})
358
359 // Setup mock search results
360 mockSearchResult := &github.CodeSearchResult{
361 Total: github.Ptr(2),
362 IncompleteResults: github.Ptr(false),
363 CodeResults: []*github.CodeResult{
364 {
365 Name: github.Ptr("file1.go"),
366 Path: github.Ptr("path/to/file1.go"),
367 SHA: github.Ptr("abc123def456"),
368 Repository: &github.Repository{
369 Name: github.Ptr("repo"),
370 FullName: github.Ptr("owner/repo"),
371 },
372 TextMatches: []*github.TextMatch{
373 {
374 Fragment: github.Ptr("func main() { fmt.Println(\"hello\") }"),
375 },
376 },
377 },
378 {
379 Name: github.Ptr("file2.go"),
380 Path: github.Ptr("path/to/file2.go"),
381 SHA: github.Ptr("def456abc123"),
382 Repository: &github.Repository{
383 Name: github.Ptr("repo"),
384 FullName: github.Ptr("owner/repo"),
385 },
386 },
387 },
388 }
389
390 textMatchAcceptHeader := map[string]string{
391 "Accept": "text-match",
392 }
393
394 tests := []struct {
395 name string
396 mockedClient *http.Client
397 requestArgs map[string]any
398 expectError bool

Callers

nothing calls this directly

Calls 15

TestFunction · 0.92
SearchCodeFunction · 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
withHeadersMethod · 0.80

Tested by

no test coverage detected