(t *testing.T)
| 121 | } |
| 122 | |
| 123 | func Test_ListCodeScanningAlerts(t *testing.T) { |
| 124 | // Verify tool definition once |
| 125 | toolDef := ListCodeScanningAlerts(translations.NullTranslationHelper) |
| 126 | require.NoError(t, toolsnaps.Test(toolDef.Tool.Name, toolDef.Tool)) |
| 127 | |
| 128 | assert.Equal(t, "list_code_scanning_alerts", toolDef.Tool.Name) |
| 129 | assert.NotEmpty(t, toolDef.Tool.Description) |
| 130 | |
| 131 | // InputSchema is of type any, need to cast to *jsonschema.Schema |
| 132 | schema, ok := toolDef.Tool.InputSchema.(*jsonschema.Schema) |
| 133 | require.True(t, ok, "InputSchema should be *jsonschema.Schema") |
| 134 | assert.Contains(t, schema.Properties, "owner") |
| 135 | assert.Contains(t, schema.Properties, "repo") |
| 136 | assert.Contains(t, schema.Properties, "ref") |
| 137 | assert.Contains(t, schema.Properties, "state") |
| 138 | assert.Contains(t, schema.Properties, "severity") |
| 139 | assert.Contains(t, schema.Properties, "tool_name") |
| 140 | assert.Contains(t, schema.Properties, "page") |
| 141 | assert.Contains(t, schema.Properties, "perPage") |
| 142 | assert.ElementsMatch(t, schema.Required, []string{"owner", "repo"}) |
| 143 | |
| 144 | // Setup mock alerts for success case |
| 145 | mockAlerts := []*github.Alert{ |
| 146 | { |
| 147 | Number: github.Ptr(42), |
| 148 | State: github.Ptr("open"), |
| 149 | Rule: &github.Rule{ID: github.Ptr("test-rule-1"), Description: github.Ptr("Test Rule 1")}, |
| 150 | HTMLURL: github.Ptr("https://github.com/owner/repo/security/code-scanning/42"), |
| 151 | }, |
| 152 | { |
| 153 | Number: github.Ptr(43), |
| 154 | State: github.Ptr("fixed"), |
| 155 | Rule: &github.Rule{ID: github.Ptr("test-rule-2"), Description: github.Ptr("Test Rule 2")}, |
| 156 | HTMLURL: github.Ptr("https://github.com/owner/repo/security/code-scanning/43"), |
| 157 | }, |
| 158 | } |
| 159 | |
| 160 | tests := []struct { |
| 161 | name string |
| 162 | mockedClient *http.Client |
| 163 | requestArgs map[string]any |
| 164 | expectError bool |
| 165 | expectedAlerts []*github.Alert |
| 166 | expectedErrMsg string |
| 167 | }{ |
| 168 | { |
| 169 | name: "successful alerts listing", |
| 170 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 171 | GetReposCodeScanningAlertsByOwnerByRepo: expectQueryParams(t, map[string]string{ |
| 172 | "ref": "main", |
| 173 | "state": "open", |
| 174 | "severity": "high", |
| 175 | "tool_name": "codeql", |
| 176 | "page": "1", |
| 177 | "per_page": "30", |
| 178 | }).andThen( |
| 179 | mockResponse(t, http.StatusOK, mockAlerts), |
| 180 | ), |
nothing calls this directly
no test coverage detected