(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func 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{ |
nothing calls this directly
no test coverage detected