(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func Test_GetSecretScanningAlert(t *testing.T) { |
| 18 | toolDef := GetSecretScanningAlert(translations.NullTranslationHelper) |
| 19 | |
| 20 | require.NoError(t, toolsnaps.Test(toolDef.Tool.Name, toolDef.Tool)) |
| 21 | |
| 22 | assert.Equal(t, "get_secret_scanning_alert", toolDef.Tool.Name) |
| 23 | assert.NotEmpty(t, toolDef.Tool.Description) |
| 24 | |
| 25 | // Verify InputSchema structure |
| 26 | schema, ok := toolDef.Tool.InputSchema.(*jsonschema.Schema) |
| 27 | require.True(t, ok, "InputSchema should be *jsonschema.Schema") |
| 28 | assert.Contains(t, schema.Properties, "owner") |
| 29 | assert.Contains(t, schema.Properties, "repo") |
| 30 | assert.Contains(t, schema.Properties, "alertNumber") |
| 31 | assert.ElementsMatch(t, schema.Required, []string{"owner", "repo", "alertNumber"}) |
| 32 | |
| 33 | // Setup mock alert for success case |
| 34 | mockAlert := &github.SecretScanningAlert{ |
| 35 | Number: github.Ptr(42), |
| 36 | State: github.Ptr("open"), |
| 37 | HTMLURL: github.Ptr("https://github.com/owner/private-repo/security/secret-scanning/42"), |
| 38 | } |
| 39 | |
| 40 | tests := []struct { |
| 41 | name string |
| 42 | mockedClient *http.Client |
| 43 | requestArgs map[string]any |
| 44 | expectError bool |
| 45 | expectedAlert *github.SecretScanningAlert |
| 46 | expectedErrMsg string |
| 47 | }{ |
| 48 | { |
| 49 | name: "successful alert fetch", |
| 50 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 51 | GetReposSecretScanningAlertsByOwnerByRepoByAlertNumber: mockResponse(t, http.StatusOK, mockAlert), |
| 52 | }), |
| 53 | requestArgs: map[string]any{ |
| 54 | "owner": "owner", |
| 55 | "repo": "repo", |
| 56 | "alertNumber": float64(42), |
| 57 | }, |
| 58 | expectError: false, |
| 59 | expectedAlert: mockAlert, |
| 60 | }, |
| 61 | { |
| 62 | name: "alert fetch fails", |
| 63 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 64 | GetReposSecretScanningAlertsByOwnerByRepoByAlertNumber: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| 65 | w.WriteHeader(http.StatusNotFound) |
| 66 | _, _ = w.Write([]byte(`{"message": "Not Found"}`)) |
| 67 | }), |
| 68 | }), |
| 69 | requestArgs: map[string]any{ |
| 70 | "owner": "owner", |
| 71 | "repo": "repo", |
| 72 | "alertNumber": float64(9999), |
| 73 | }, |
| 74 | expectError: true, |
nothing calls this directly
no test coverage detected