MCPcopy
hub / github.com/cli/cli / TestListSessionsByResourceID

Function TestListSessionsByResourceID

pkg/cmd/agent-task/capi/sessions_test.go:1199–1565  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1197}
1198
1199func TestListSessionsByResourceID(t *testing.T) {
1200 sampleDateString := "2025-08-29T07:00:00Z"
1201 sampleDate, err := time.Parse(time.RFC3339, sampleDateString)
1202 require.NoError(t, err)
1203 sampleDateTimestamp := sampleDate.Unix()
1204
1205 resourceID := int64(999)
1206 resourceType := "pull"
1207
1208 tests := []struct {
1209 name string
1210 perPage int
1211 limit int
1212 httpStubs func(*testing.T, *httpmock.Registry)
1213 wantErr string
1214 wantOut []*Session
1215 }{
1216 {
1217 name: "zero limit",
1218 limit: 0,
1219 wantOut: nil,
1220 },
1221 {
1222 // If the given pull request does not exist or the pull request has no sessions,
1223 // the API endpoint returns 404 with different messages. We should treat them
1224 // the same though.
1225 name: "no sessions or no pull request",
1226 limit: 10,
1227 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
1228 reg.Register(
1229 httpmock.WithHost(httpmock.REST("GET", "agents/resource/pull/999"), "api.githubcopilot.com"),
1230
1231 httpmock.StatusStringResponse(404, "{}"),
1232 )
1233 },
1234 wantErr: "failed to list sessions",
1235 },
1236 {
1237 name: "single session",
1238 limit: 10,
1239 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
1240 reg.Register(
1241 httpmock.WithHost(httpmock.REST("GET", "agents/resource/pull/999"), "api.githubcopilot.com"),
1242 httpmock.StringResponse(heredoc.Docf(`
1243 {
1244 "id": "resource:pull:2000",
1245 "user_id": 1,
1246 "resource_global_id": "PR_kwDNA-jNB9A",
1247 "resource_type": "pull",
1248 "resource_id": 2000,
1249 "session_count": 1,
1250 "last_updated_at": %[1]d,
1251 "state": "completed",
1252 "resource_state": "draft",
1253 "sessions": [
1254 {
1255 "id": "sess1",
1256 "name": "Build artifacts",

Callers

nothing calls this directly

Calls 12

RegisterMethod · 0.95
VerifyMethod · 0.95
WithHostFunction · 0.92
RESTFunction · 0.92
StatusStringResponseFunction · 0.92
StringResponseFunction · 0.92
GraphQLFunction · 0.92
GraphQLQueryFunction · 0.92
NewCAPIClientFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected