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

Function Test_ListDependabotAlerts

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

Source from the content-addressed store, hash-verified

126}
127
128func Test_ListDependabotAlerts(t *testing.T) {
129 // Verify tool definition once
130 toolDef := ListDependabotAlerts(translations.NullTranslationHelper)
131 tool := toolDef.Tool
132 require.NoError(t, toolsnaps.Test(tool.Name, tool))
133
134 assert.Equal(t, "list_dependabot_alerts", tool.Name)
135 assert.NotEmpty(t, tool.Description)
136 assert.True(t, tool.Annotations.ReadOnlyHint, "list_dependabot_alerts tool should be read-only")
137
138 // Setup mock alerts for success case
139 criticalAlert := github.DependabotAlert{
140 Number: github.Ptr(1),
141 HTMLURL: github.Ptr("https://github.com/owner/repo/security/dependabot/1"),
142 State: github.Ptr("open"),
143 SecurityAdvisory: &github.DependabotSecurityAdvisory{
144 Severity: github.Ptr("critical"),
145 },
146 }
147 highSeverityAlert := github.DependabotAlert{
148 Number: github.Ptr(2),
149 HTMLURL: github.Ptr("https://github.com/owner/repo/security/dependabot/2"),
150 State: github.Ptr("fixed"),
151 SecurityAdvisory: &github.DependabotSecurityAdvisory{
152 Severity: github.Ptr("high"),
153 },
154 }
155
156 tests := []struct {
157 name string
158 mockedClient *http.Client
159 requestArgs map[string]any
160 expectError bool
161 expectedAlerts []*github.DependabotAlert
162 expectedNextCursor string
163 expectedErrMsg string
164 }{
165 {
166 name: "successful open alerts listing",
167 mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
168 GetReposDependabotAlertsByOwnerByRepo: expectQueryParams(t, map[string]string{
169 "state": "open",
170 "per_page": "30",
171 }).andThen(
172 mockResponse(t, http.StatusOK, []*github.DependabotAlert{&criticalAlert}),
173 ),
174 }),
175 requestArgs: map[string]any{
176 "owner": "owner",
177 "repo": "repo",
178 "state": "open",
179 },
180 expectError: false,
181 expectedAlerts: []*github.DependabotAlert{&criticalAlert},
182 },
183 {
184 name: "successful severity filtered listing",
185 mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{

Callers

nothing calls this directly

Calls 15

TestFunction · 0.92
ListDependabotAlertsFunction · 0.85
expectQueryParamsFunction · 0.85
mockResponseFunction · 0.85
mustNewGHClientFunction · 0.85
createMCPRequestFunction · 0.85
ContextWithDepsFunction · 0.85
getErrorResultFunction · 0.85
getTextResultFunction · 0.85
andThenMethod · 0.80
HeaderMethod · 0.80

Tested by

no test coverage detected