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

Function Test_StarRepository

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

Source from the content-addressed store, hash-verified

4548}
4549
4550func Test_StarRepository(t *testing.T) {
4551 // Verify tool definition once
4552 serverTool := StarRepository(translations.NullTranslationHelper)
4553 tool := serverTool.Tool
4554 require.NoError(t, toolsnaps.Test(tool.Name, tool))
4555
4556 schema, ok := tool.InputSchema.(*jsonschema.Schema)
4557 require.True(t, ok, "InputSchema should be *jsonschema.Schema")
4558
4559 assert.Equal(t, "star_repository", tool.Name)
4560 assert.NotEmpty(t, tool.Description)
4561 assert.Contains(t, schema.Properties, "owner")
4562 assert.Contains(t, schema.Properties, "repo")
4563 assert.ElementsMatch(t, schema.Required, []string{"owner", "repo"})
4564
4565 tests := []struct {
4566 name string
4567 mockedClient *http.Client
4568 requestArgs map[string]any
4569 expectError bool
4570 expectedErrMsg string
4571 }{
4572 {
4573 name: "successful star",
4574 mockedClient: NewMockedHTTPClient(
4575 WithRequestMatchHandler(
4576 PutUserStarredByOwnerByRepo,
4577 http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
4578 w.WriteHeader(http.StatusNoContent)
4579 }),
4580 ),
4581 ),
4582 requestArgs: map[string]any{
4583 "owner": "testowner",
4584 "repo": "testrepo",
4585 },
4586 expectError: false,
4587 },
4588 {
4589 name: "star fails",
4590 mockedClient: NewMockedHTTPClient(
4591 WithRequestMatchHandler(
4592 PutUserStarredByOwnerByRepo,
4593 http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
4594 w.WriteHeader(http.StatusNotFound)
4595 _, _ = w.Write([]byte(`{"message": "Not Found"}`))
4596 }),
4597 ),
4598 ),
4599 requestArgs: map[string]any{
4600 "owner": "testowner",
4601 "repo": "nonexistent",
4602 },
4603 expectError: true,
4604 expectedErrMsg: "failed to star repository",
4605 },
4606 }
4607

Callers

nothing calls this directly

Calls 11

TestFunction · 0.92
StarRepositoryFunction · 0.85
WithRequestMatchHandlerFunction · 0.85
mustNewGHClientFunction · 0.85
createMCPRequestFunction · 0.85
ContextWithDepsFunction · 0.85
getTextResultFunction · 0.85
WriteHeaderMethod · 0.80
NewMockedHTTPClientFunction · 0.70
WriteMethod · 0.45
HandlerMethod · 0.45

Tested by

no test coverage detected