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

Function Test_GetDependabotAlert

pkg/github/dependabot_test.go:16–126  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func Test_GetDependabotAlert(t *testing.T) {
17 // Verify tool definition
18 toolDef := GetDependabotAlert(translations.NullTranslationHelper)
19 tool := toolDef.Tool
20 require.NoError(t, toolsnaps.Test(tool.Name, tool))
21
22 // Validate tool schema
23 assert.Equal(t, "get_dependabot_alert", tool.Name)
24 assert.NotEmpty(t, tool.Description)
25 assert.True(t, tool.Annotations.ReadOnlyHint, "get_dependabot_alert tool should be read-only")
26
27 // Setup mock alert for success case
28 mockAlert := &github.DependabotAlert{
29 Number: github.Ptr(42),
30 State: github.Ptr("open"),
31 HTMLURL: github.Ptr("https://github.com/owner/repo/security/dependabot/42"),
32 }
33
34 tests := []struct {
35 name string
36 mockedClient *http.Client
37 requestArgs map[string]any
38 expectError bool
39 expectedAlert *github.DependabotAlert
40 expectedErrMsg string
41 }{
42 {
43 name: "successful alert fetch",
44 mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
45 GetReposDependabotAlertsByOwnerByRepoByAlertNumber: mockResponse(t, http.StatusOK, mockAlert),
46 }),
47 requestArgs: map[string]any{
48 "owner": "owner",
49 "repo": "repo",
50 "alertNumber": float64(42),
51 },
52 expectError: false,
53 expectedAlert: mockAlert,
54 },
55 {
56 name: "alert fetch fails",
57 mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
58 GetReposDependabotAlertsByOwnerByRepoByAlertNumber: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
59 w.WriteHeader(http.StatusNotFound)
60 _, _ = w.Write([]byte(`{"message": "Not Found"}`))
61 }),
62 }),
63 requestArgs: map[string]any{
64 "owner": "owner",
65 "repo": "repo",
66 "alertNumber": float64(9999),
67 },
68 expectError: true,
69 expectedErrMsg: "Your token may not have access to Dependabot alerts on owner/repo",
70 },
71 {
72 name: "alert fetch forbidden",
73 mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{

Callers

nothing calls this directly

Calls 12

TestFunction · 0.92
GetDependabotAlertFunction · 0.85
mockResponseFunction · 0.85
mustNewGHClientFunction · 0.85
createMCPRequestFunction · 0.85
ContextWithDepsFunction · 0.85
getErrorResultFunction · 0.85
getTextResultFunction · 0.85
WriteHeaderMethod · 0.80
WriteMethod · 0.45
HandlerMethod · 0.45

Tested by

no test coverage detected