MCPcopy
hub / github.com/github/github-mcp-server / Test_GetCommit

Function Test_GetCommit

pkg/github/repositories_test.go:1025–1152  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1023}
1024
1025func Test_GetCommit(t *testing.T) {
1026 // Verify tool definition once
1027 serverTool := GetCommit(translations.NullTranslationHelper)
1028 tool := serverTool.Tool
1029 require.NoError(t, toolsnaps.Test(tool.Name, tool))
1030
1031 schema, ok := tool.InputSchema.(*jsonschema.Schema)
1032 require.True(t, ok, "InputSchema should be *jsonschema.Schema")
1033
1034 assert.Equal(t, "get_commit", tool.Name)
1035 assert.NotEmpty(t, tool.Description)
1036 assert.Contains(t, schema.Properties, "owner")
1037 assert.Contains(t, schema.Properties, "repo")
1038 assert.Contains(t, schema.Properties, "sha")
1039 assert.ElementsMatch(t, schema.Required, []string{"owner", "repo", "sha"})
1040
1041 mockCommit := &github.RepositoryCommit{
1042 SHA: github.Ptr("abc123def456"),
1043 Commit: &github.Commit{
1044 Message: github.Ptr("First commit"),
1045 Author: &github.CommitAuthor{
1046 Name: github.Ptr("Test User"),
1047 Email: github.Ptr("test@example.com"),
1048 Date: &github.Timestamp{Time: time.Now().Add(-48 * time.Hour)},
1049 },
1050 },
1051 Author: &github.User{
1052 Login: github.Ptr("testuser"),
1053 },
1054 HTMLURL: github.Ptr("https://github.com/owner/repo/commit/abc123def456"),
1055 Stats: &github.CommitStats{
1056 Additions: github.Ptr(10),
1057 Deletions: github.Ptr(2),
1058 Total: github.Ptr(12),
1059 },
1060 Files: []*github.CommitFile{
1061 {
1062 Filename: github.Ptr("file1.go"),
1063 Status: github.Ptr("modified"),
1064 Additions: github.Ptr(10),
1065 Deletions: github.Ptr(2),
1066 Changes: github.Ptr(12),
1067 Patch: github.Ptr("@@ -1,2 +1,10 @@"),
1068 },
1069 },
1070 }
1071
1072 tests := []struct {
1073 name string
1074 mockedClient *http.Client
1075 requestArgs map[string]any
1076 expectError bool
1077 expectedCommit *github.RepositoryCommit
1078 expectedErrMsg string
1079 }{
1080 {
1081 name: "successful commit fetch",
1082 mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{

Callers

nothing calls this directly

Calls 13

TestFunction · 0.92
GetCommitFunction · 0.85
mockResponseFunction · 0.85
mustNewGHClientFunction · 0.85
createMCPRequestFunction · 0.85
ContextWithDepsFunction · 0.85
getErrorResultFunction · 0.85
getTextResultFunction · 0.85
AddMethod · 0.80
WriteHeaderMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected