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

Function Test_DeleteFile

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

Source from the content-addressed store, hash-verified

2987}
2988
2989func Test_DeleteFile(t *testing.T) {
2990 // Verify tool definition once
2991 serverTool := DeleteFile(translations.NullTranslationHelper)
2992 tool := serverTool.Tool
2993 require.NoError(t, toolsnaps.Test(tool.Name, tool))
2994
2995 schema, ok := tool.InputSchema.(*jsonschema.Schema)
2996 require.True(t, ok, "InputSchema should be *jsonschema.Schema")
2997
2998 assert.Equal(t, "delete_file", tool.Name)
2999 assert.NotEmpty(t, tool.Description)
3000 assert.Contains(t, schema.Properties, "owner")
3001 assert.Contains(t, schema.Properties, "repo")
3002 assert.Contains(t, schema.Properties, "path")
3003 assert.Contains(t, schema.Properties, "message")
3004 assert.Contains(t, schema.Properties, "branch")
3005 // SHA is no longer required since we're using Git Data API
3006 assert.ElementsMatch(t, schema.Required, []string{"owner", "repo", "path", "message", "branch"})
3007
3008 // Setup mock objects for Git Data API
3009 mockRef := &github.Reference{
3010 Ref: github.Ptr("refs/heads/main"),
3011 Object: &github.GitObject{
3012 SHA: github.Ptr("abc123"),
3013 },
3014 }
3015
3016 mockCommit := &github.Commit{
3017 SHA: github.Ptr("abc123"),
3018 Tree: &github.Tree{
3019 SHA: github.Ptr("def456"),
3020 },
3021 }
3022
3023 mockTree := &github.Tree{
3024 SHA: github.Ptr("ghi789"),
3025 }
3026
3027 mockNewCommit := &github.Commit{
3028 SHA: github.Ptr("jkl012"),
3029 Message: github.Ptr("Delete example file"),
3030 HTMLURL: github.Ptr("https://github.com/owner/repo/commit/jkl012"),
3031 }
3032
3033 tests := []struct {
3034 name string
3035 mockedClient *http.Client
3036 requestArgs map[string]any
3037 expectError bool
3038 expectedCommitSHA string
3039 expectedErrMsg string
3040 }{
3041 {
3042 name: "successful file deletion using Git Data API",
3043 mockedClient: NewMockedHTTPClient(
3044 // Get branch reference
3045 WithRequestMatch(
3046 GetReposGitRefByOwnerByRepoByRef,

Callers

nothing calls this directly

Calls 15

TestFunction · 0.92
DeleteFileFunction · 0.85
WithRequestMatchFunction · 0.85
WithRequestMatchHandlerFunction · 0.85
expectRequestBodyFunction · 0.85
mockResponseFunction · 0.85
mustNewGHClientFunction · 0.85
createMCPRequestFunction · 0.85
ContextWithDepsFunction · 0.85
getTextResultFunction · 0.85
andThenMethod · 0.80
WriteHeaderMethod · 0.80

Tested by

no test coverage detected