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

Function Test_CreateBranch

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

Source from the content-addressed store, hash-verified

846}
847
848func Test_CreateBranch(t *testing.T) {
849 // Verify tool definition once
850 serverTool := CreateBranch(translations.NullTranslationHelper)
851 tool := serverTool.Tool
852 require.NoError(t, toolsnaps.Test(tool.Name, tool))
853
854 schema, ok := tool.InputSchema.(*jsonschema.Schema)
855 require.True(t, ok, "InputSchema should be *jsonschema.Schema")
856
857 assert.Equal(t, "create_branch", tool.Name)
858 assert.NotEmpty(t, tool.Description)
859 assert.Contains(t, schema.Properties, "owner")
860 assert.Contains(t, schema.Properties, "repo")
861 assert.Contains(t, schema.Properties, "branch")
862 assert.Contains(t, schema.Properties, "from_branch")
863 assert.ElementsMatch(t, schema.Required, []string{"owner", "repo", "branch"})
864
865 // Setup mock repository for default branch test
866 mockRepo := &github.Repository{
867 DefaultBranch: github.Ptr("main"),
868 }
869
870 // Setup mock reference for from_branch tests
871 mockSourceRef := &github.Reference{
872 Ref: github.Ptr("refs/heads/main"),
873 Object: &github.GitObject{
874 SHA: github.Ptr("abc123def456"),
875 },
876 }
877
878 // Setup mock created reference
879 mockCreatedRef := &github.Reference{
880 Ref: github.Ptr("refs/heads/new-feature"),
881 Object: &github.GitObject{
882 SHA: github.Ptr("abc123def456"),
883 },
884 }
885
886 tests := []struct {
887 name string
888 mockedClient *http.Client
889 requestArgs map[string]any
890 expectError bool
891 expectedRef *github.Reference
892 expectedErrMsg string
893 }{
894 {
895 name: "successful branch creation with from_branch",
896 mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
897 GetReposGitRefByOwnerByRepoByRef: mockResponse(t, http.StatusOK, mockSourceRef),
898 "GET /repos/owner/repo/git/ref/heads/main": mockResponse(t, http.StatusOK, mockSourceRef),
899 PostReposGitRefsByOwnerByRepo: mockResponse(t, http.StatusCreated, mockCreatedRef),
900 }),
901 requestArgs: map[string]any{
902 "owner": "owner",
903 "repo": "repo",
904 "branch": "new-feature",
905 "from_branch": "main",

Callers

nothing calls this directly

Calls 14

TestFunction · 0.92
CreateBranchFunction · 0.85
mockResponseFunction · 0.85
expectRequestBodyFunction · 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