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

Function Test_CreateRepository

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

Source from the content-addressed store, hash-verified

1933}
1934
1935func Test_CreateRepository(t *testing.T) {
1936 // Verify tool definition once
1937 serverTool := CreateRepository(translations.NullTranslationHelper)
1938 tool := serverTool.Tool
1939 require.NoError(t, toolsnaps.Test(tool.Name, tool))
1940
1941 schema, ok := tool.InputSchema.(*jsonschema.Schema)
1942 require.True(t, ok, "InputSchema should be *jsonschema.Schema")
1943
1944 assert.Equal(t, "create_repository", tool.Name)
1945 assert.NotEmpty(t, tool.Description)
1946 assert.Contains(t, schema.Properties, "name")
1947 assert.Contains(t, schema.Properties, "description")
1948 assert.Contains(t, schema.Properties, "organization")
1949 assert.Contains(t, schema.Properties, "private")
1950 assert.Contains(t, schema.Properties, "autoInit")
1951 assert.ElementsMatch(t, schema.Required, []string{"name"})
1952
1953 // Setup mock repository response
1954 mockRepo := &github.Repository{
1955 Name: github.Ptr("test-repo"),
1956 Description: github.Ptr("Test repository"),
1957 Private: github.Ptr(true),
1958 HTMLURL: github.Ptr("https://github.com/testuser/test-repo"),
1959 CreatedAt: &github.Timestamp{Time: time.Now()},
1960 Owner: &github.User{
1961 Login: github.Ptr("testuser"),
1962 },
1963 }
1964
1965 tests := []struct {
1966 name string
1967 mockedClient *http.Client
1968 requestArgs map[string]any
1969 expectError bool
1970 expectedRepo *github.Repository
1971 expectedErrMsg string
1972 }{
1973 {
1974 name: "successful repository creation with all parameters",
1975 mockedClient: NewMockedHTTPClient(
1976 WithRequestMatchHandler(
1977 EndpointPattern("POST /user/repos"),
1978 expectRequestBody(t, map[string]any{
1979 "name": "test-repo",
1980 "description": "Test repository",
1981 "private": true,
1982 "auto_init": true,
1983 }).andThen(
1984 mockResponse(t, http.StatusCreated, mockRepo),
1985 ),
1986 ),
1987 ),
1988 requestArgs: map[string]any{
1989 "name": "test-repo",
1990 "description": "Test repository",
1991 "private": true,
1992 "autoInit": true,

Callers

nothing calls this directly

Calls 15

TestFunction · 0.92
CreateRepositoryFunction · 0.85
WithRequestMatchHandlerFunction · 0.85
EndpointPatternTypeAlias · 0.85
expectRequestBodyFunction · 0.85
mockResponseFunction · 0.85
mustNewGHClientFunction · 0.85
createMCPRequestFunction · 0.85
ContextWithDepsFunction · 0.85
getErrorResultFunction · 0.85
getTextResultFunction · 0.85
andThenMethod · 0.80

Tested by

no test coverage detected