(t *testing.T)
| 126 | } |
| 127 | |
| 128 | func 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{ |
nothing calls this directly
no test coverage detected