(t *testing.T)
| 1572 | } |
| 1573 | |
| 1574 | func TestGetSession(t *testing.T) { |
| 1575 | sampleDateString := "2025-08-29T00:00:00Z" |
| 1576 | sampleDate, err := time.Parse(time.RFC3339, sampleDateString) |
| 1577 | require.NoError(t, err) |
| 1578 | |
| 1579 | tests := []struct { |
| 1580 | name string |
| 1581 | httpStubs func(*testing.T, *httpmock.Registry) |
| 1582 | wantErr string |
| 1583 | wantErrIs error |
| 1584 | wantOut *Session |
| 1585 | }{ |
| 1586 | { |
| 1587 | name: "session not found", |
| 1588 | httpStubs: func(t *testing.T, reg *httpmock.Registry) { |
| 1589 | reg.Register( |
| 1590 | httpmock.WithHost(httpmock.REST("GET", "agents/sessions/some-uuid"), "api.githubcopilot.com"), |
| 1591 | httpmock.StatusStringResponse(404, "{}"), |
| 1592 | ) |
| 1593 | }, |
| 1594 | wantErrIs: ErrSessionNotFound, |
| 1595 | wantErr: "not found", |
| 1596 | }, |
| 1597 | { |
| 1598 | name: "API error", |
| 1599 | httpStubs: func(t *testing.T, reg *httpmock.Registry) { |
| 1600 | reg.Register( |
| 1601 | httpmock.WithHost(httpmock.REST("GET", "agents/sessions/some-uuid"), "api.githubcopilot.com"), |
| 1602 | httpmock.StatusStringResponse(500, "some error"), |
| 1603 | ) |
| 1604 | }, |
| 1605 | wantErr: "failed to get session:", |
| 1606 | }, |
| 1607 | { |
| 1608 | name: "invalid JSON response", |
| 1609 | httpStubs: func(t *testing.T, reg *httpmock.Registry) { |
| 1610 | reg.Register( |
| 1611 | httpmock.WithHost(httpmock.REST("GET", "agents/sessions/some-uuid"), "api.githubcopilot.com"), |
| 1612 | httpmock.StatusStringResponse(200, ""), |
| 1613 | ) |
| 1614 | }, |
| 1615 | wantErr: "failed to decode session response: EOF", |
| 1616 | }, |
| 1617 | { |
| 1618 | name: "success", |
| 1619 | httpStubs: func(t *testing.T, reg *httpmock.Registry) { |
| 1620 | reg.Register( |
| 1621 | httpmock.WithHost(httpmock.REST("GET", "agents/sessions/some-uuid"), "api.githubcopilot.com"), |
| 1622 | httpmock.StringResponse(heredoc.Docf(` |
| 1623 | { |
| 1624 | "id": "some-uuid", |
| 1625 | "name": "Build artifacts", |
| 1626 | "user_id": 1, |
| 1627 | "agent_id": 2, |
| 1628 | "logs": "", |
| 1629 | "state": "completed", |
| 1630 | "owner_id": 10, |
| 1631 | "repo_id": 1000, |
nothing calls this directly
no test coverage detected