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

Function Test_ListGists

pkg/github/gists_test.go:18–184  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func Test_ListGists(t *testing.T) {
19 // Verify tool definition
20 serverTool := ListGists(translations.NullTranslationHelper)
21 tool := serverTool.Tool
22
23 require.NoError(t, toolsnaps.Test(tool.Name, tool))
24
25 assert.Equal(t, "list_gists", tool.Name)
26 assert.NotEmpty(t, tool.Description)
27 assert.True(t, tool.Annotations.ReadOnlyHint, "list_gists tool should be read-only")
28
29 schema, ok := tool.InputSchema.(*jsonschema.Schema)
30 require.True(t, ok, "InputSchema should be *jsonschema.Schema")
31 assert.Contains(t, schema.Properties, "username")
32 assert.Contains(t, schema.Properties, "since")
33 assert.Contains(t, schema.Properties, "page")
34 assert.Contains(t, schema.Properties, "perPage")
35 assert.Empty(t, schema.Required)
36
37 // Setup mock gists for success case
38 mockGists := []*github.Gist{
39 {
40 ID: github.Ptr("gist1"),
41 Description: github.Ptr("First Gist"),
42 HTMLURL: github.Ptr("https://gist.github.com/user/gist1"),
43 Public: github.Ptr(true),
44 CreatedAt: &github.Timestamp{Time: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)},
45 Owner: &github.User{Login: github.Ptr("user")},
46 Files: map[github.GistFilename]github.GistFile{
47 "file1.txt": {
48 Filename: github.Ptr("file1.txt"),
49 Content: github.Ptr("content of file 1"),
50 },
51 },
52 },
53 {
54 ID: github.Ptr("gist2"),
55 Description: github.Ptr("Second Gist"),
56 HTMLURL: github.Ptr("https://gist.github.com/testuser/gist2"),
57 Public: github.Ptr(false),
58 CreatedAt: &github.Timestamp{Time: time.Date(2023, 2, 1, 0, 0, 0, 0, time.UTC)},
59 Owner: &github.User{Login: github.Ptr("testuser")},
60 Files: map[github.GistFilename]github.GistFile{
61 "file2.js": {
62 Filename: github.Ptr("file2.js"),
63 Content: github.Ptr("console.log('hello');"),
64 },
65 },
66 },
67 }
68
69 tests := []struct {
70 name string
71 mockedClient *http.Client
72 requestArgs map[string]any
73 expectError bool
74 expectedGists []*github.Gist
75 expectedErrMsg string

Callers

nothing calls this directly

Calls 14

TestFunction · 0.92
ListGistsFunction · 0.85
mockResponseFunction · 0.85
expectQueryParamsFunction · 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