Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit47fdf2e

Browse files
committed
fix tests
1 parent5dbfaa8 commit47fdf2e

File tree

2 files changed

+47
-55
lines changed

2 files changed

+47
-55
lines changed

‎pkg/github/secret_scanning.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,16 @@ func ListSecretScanningAlerts(getClient GetClientFn, t translations.TranslationH
8585
mcp.Description("The name of the repository."),
8686
),
8787
mcp.WithString("state",
88-
mcp.Description("Filtercode scanning alertsby state ('open', 'resolved')"),
88+
mcp.Description("Filter by state"),
8989
mcp.Enum("open","resolved"),
9090
),
9191
mcp.WithString("secret_type",
9292
mcp.Description("A comma-separated list of secret types to return. All default secret patterns are returned. To return generic patterns, pass the token name(s) in the parameter."),
9393
),
9494
mcp.WithString("resolution",
95-
mcp.Description("Filtercode scanning alertsby resolution ('false_positive', 'wont_fix', 'revoked', 'pattern_edited', 'pattern_deleted', 'used_in_tests')"),
95+
mcp.Description("Filter by resolution"),
9696
mcp.Enum("false_positive","wont_fix","revoked","pattern_edited","pattern_deleted","used_in_tests"),
9797
),
98-
mcp.WithString("sort",
99-
mcp.Description("Filter code scanning alerts by sort ('created', 'updated') Default: created"),
100-
mcp.DefaultString("created"),
101-
mcp.Enum("created","updated"),
102-
),
103-
mcp.WithString("direction",
104-
mcp.Description("Filter code scanning alerts by direction ('desc', 'asc') Default: desc"),
105-
mcp.DefaultString("desc"),
106-
mcp.Enum("desc","asc"),
107-
),
10898
),
10999
func(ctx context.Context,request mcp.CallToolRequest) (*mcp.CallToolResult,error) {
110100
owner,err:=requiredParam[string](request,"owner")
@@ -127,20 +117,12 @@ func ListSecretScanningAlerts(getClient GetClientFn, t translations.TranslationH
127117
iferr!=nil {
128118
returnmcp.NewToolResultError(err.Error()),nil
129119
}
130-
sort,err:=OptionalParam[string](request,"sort")
131-
iferr!=nil {
132-
returnmcp.NewToolResultError(err.Error()),nil
133-
}
134-
direction,err:=OptionalParam[string](request,"direction")
135-
iferr!=nil {
136-
returnmcp.NewToolResultError(err.Error()),nil
137-
}
138120

139121
client,err:=getClient(ctx)
140122
iferr!=nil {
141123
returnnil,fmt.Errorf("failed to get GitHub client: %w",err)
142124
}
143-
alerts,resp,err:=client.SecretScanning.ListAlertsForRepo(ctx,owner,repo,&github.SecretScanningAlertListOptions{State:state,SecretType:secretType,Resolution:resolution,Sort:sort,Direction:direction})
125+
alerts,resp,err:=client.SecretScanning.ListAlertsForRepo(ctx,owner,repo,&github.SecretScanningAlertListOptions{State:state,SecretType:secretType,Resolution:resolution})
144126
iferr!=nil {
145127
returnnil,fmt.Errorf("failed to list alerts: %w",err)
146128
}

‎pkg/github/secret_scanning_test.go

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ func Test_GetSecretScanningAlert(t *testing.T) {
2626

2727
// Setup mock alert for success case
2828
mockAlert:=&github.SecretScanningAlert{
29-
Number:github.Ptr(42),
30-
State:github.Ptr("open"),
29+
Number:github.Ptr(42),
30+
State:github.Ptr("open"),
3131
HTMLURL:github.Ptr("https://github.com/owner/private-repo/security/secret-scanning/42"),
3232
}
3333

@@ -124,22 +124,22 @@ func Test_ListSecretScanningAlerts(t *testing.T) {
124124
assert.Contains(t,tool.InputSchema.Properties,"state")
125125
assert.Contains(t,tool.InputSchema.Properties,"secret_type")
126126
assert.Contains(t,tool.InputSchema.Properties,"resolution")
127-
assert.Contains(t,tool.InputSchema.Properties,"sort")
128-
assert.Contains(t,tool.InputSchema.Properties,"direction")
129127
assert.ElementsMatch(t,tool.InputSchema.Required, []string{"owner","repo"})
130128

131129
// Setup mock alerts for success case
132-
mockAlerts:= []*github.SecretScanningAlert{
133-
{
134-
Number:github.Ptr(42),
135-
State:github.Ptr("open"),
136-
HTMLURL:github.Ptr("https://github.com/owner/repo/security/code-scanning/42"),
137-
},
138-
{
139-
Number:github.Ptr(43),
140-
State:github.Ptr("fixed"),
141-
HTMLURL:github.Ptr("https://github.com/owner/repo/security/code-scanning/43"),
142-
},
130+
resolvedAlert:= github.SecretScanningAlert{
131+
Number:github.Ptr(2),
132+
HTMLURL:github.Ptr("https://github.com/owner/private-repo/security/secret-scanning/2"),
133+
State:github.Ptr("resolved"),
134+
Resolution:github.Ptr("false_positive"),
135+
SecretType:github.Ptr("adafruit_io_key"),
136+
}
137+
openAlert:= github.SecretScanningAlert{
138+
Number:github.Ptr(2),
139+
HTMLURL:github.Ptr("https://github.com/owner/private-repo/security/secret-scanning/3"),
140+
State:github.Ptr("open"),
141+
Resolution:github.Ptr("false_positive"),
142+
SecretType:github.Ptr("adafruit_io_key"),
143143
}
144144

145145
tests:= []struct {
@@ -151,28 +151,41 @@ func Test_ListSecretScanningAlerts(t *testing.T) {
151151
expectedErrMsgstring
152152
}{
153153
{
154-
name:"successful alerts listing",
154+
name:"successfulresolvedalerts listing",
155155
mockedClient:mock.NewMockedHTTPClient(
156156
mock.WithRequestMatchHandler(
157-
mock.GetReposSecretScanningAlertsByOwnerByRepoByAlertNumber,
157+
mock.GetReposSecretScanningAlertsByOwnerByRepo,
158158
expectQueryParams(t,map[string]string{
159-
"ref":"main",
160-
"state":"open",
161-
"severity":"high",
159+
"state":"resolved",
162160
}).andThen(
163-
mockResponse(t,http.StatusOK,mockAlerts),
161+
mockResponse(t,http.StatusOK,[]*github.SecretScanningAlert{&resolvedAlert}),
164162
),
165163
),
166164
),
167165
requestArgs:map[string]interface{}{
168-
"owner":"owner",
169-
"repo":"repo",
170-
"ref":"main",
171-
"state":"open",
172-
"severity":"high",
166+
"owner":"owner",
167+
"repo":"repo",
168+
"state":"resolved",
173169
},
174170
expectError:false,
175-
expectedAlerts:mockAlerts,
171+
expectedAlerts: []*github.SecretScanningAlert{&resolvedAlert},
172+
},
173+
{
174+
name:"successful alerts listing",
175+
mockedClient:mock.NewMockedHTTPClient(
176+
mock.WithRequestMatchHandler(
177+
mock.GetReposSecretScanningAlertsByOwnerByRepo,
178+
expectQueryParams(t,map[string]string{}).andThen(
179+
mockResponse(t,http.StatusOK, []*github.SecretScanningAlert{&resolvedAlert,&openAlert}),
180+
),
181+
),
182+
),
183+
requestArgs:map[string]interface{}{
184+
"owner":"owner",
185+
"repo":"repo",
186+
},
187+
expectError:false,
188+
expectedAlerts: []*github.SecretScanningAlert{&resolvedAlert,&openAlert},
176189
},
177190
{
178191
name:"alerts listing fails",
@@ -196,17 +209,13 @@ func Test_ListSecretScanningAlerts(t *testing.T) {
196209

197210
for_,tc:=rangetests {
198211
t.Run(tc.name,func(t*testing.T) {
199-
// Setup client with mock
200212
client:=github.NewClient(tc.mockedClient)
201213
_,handler:=ListSecretScanningAlerts(stubGetClientFn(client),translations.NullTranslationHelper)
202214

203-
// Create call request
204215
request:=createMCPRequest(tc.requestArgs)
205216

206-
// Call handler
207217
result,err:=handler(context.Background(),request)
208218

209-
// Verify results
210219
iftc.expectError {
211220
require.Error(t,err)
212221
assert.Contains(t,err.Error(),tc.expectedErrMsg)
@@ -215,18 +224,19 @@ func Test_ListSecretScanningAlerts(t *testing.T) {
215224

216225
require.NoError(t,err)
217226

218-
// Parse the result and get the text content if no error
219227
textContent:=getTextResult(t,result)
220228

221229
// Unmarshal and verify the result
222-
varreturnedAlerts []*github.Alert
230+
varreturnedAlerts []*github.SecretScanningAlert
223231
err=json.Unmarshal([]byte(textContent.Text),&returnedAlerts)
224232
assert.NoError(t,err)
225233
assert.Len(t,returnedAlerts,len(tc.expectedAlerts))
226234
fori,alert:=rangereturnedAlerts {
227235
assert.Equal(t,*tc.expectedAlerts[i].Number,*alert.Number)
228-
assert.Equal(t,*tc.expectedAlerts[i].State,*alert.State)
229236
assert.Equal(t,*tc.expectedAlerts[i].HTMLURL,*alert.HTMLURL)
237+
assert.Equal(t,*tc.expectedAlerts[i].State,*alert.State)
238+
assert.Equal(t,*tc.expectedAlerts[i].Resolution,*alert.Resolution)
239+
assert.Equal(t,*tc.expectedAlerts[i].SecretType,*alert.SecretType)
230240
}
231241
})
232242
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp