Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 868
Implement pagination with link headers for Adoptium based apis#1014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
dc9d954ff272af7ee69bea22487f3b472a4870106f9663ddbb5ba67cb06c5c8284c50b88aa1d800de92d16c13166782942File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,6 +9,7 @@ import * as core from '@actions/core'; | ||
| describe('getAvailableVersions', () => { | ||
| let spyHttpClient: jest.SpyInstance; | ||
| let spyCoreError: jest.SpyInstance; | ||
| let spyCoreWarning: jest.SpyInstance; | ||
| beforeEach(() => { | ||
| spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson'); | ||
| @@ -20,6 +21,8 @@ describe('getAvailableVersions', () => { | ||
| // Mock core.error to suppress error logs | ||
| spyCoreError = jest.spyOn(core, 'error'); | ||
| spyCoreError.mockImplementation(() => {}); | ||
| spyCoreWarning = jest.spyOn(core, 'warning'); | ||
| spyCoreWarning.mockImplementation(() => {}); | ||
| }); | ||
| afterEach(() => { | ||
| @@ -82,22 +85,19 @@ describe('getAvailableVersions', () => { | ||
| ); | ||
| it('load available versions', async () => { | ||
| const nextPageUrl = | ||
| 'https://api.adoptopenjdk.net/v3/assets/version/%5B1.0,100.0%5D?page=1&page_size=20'; | ||
| spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson'); | ||
| spyHttpClient | ||
| .mockReturnValueOnce({ | ||
| statusCode: 200, | ||
| headers: {}, | ||
| headers: {link: `<${nextPageUrl}>; rel="next"`}, | ||
| result: manifestData as any | ||
| }) | ||
| .mockReturnValueOnce({ | ||
| statusCode: 200, | ||
| headers: {}, | ||
| result: manifestData as any | ||
| }) | ||
| .mockReturnValueOnce({ | ||
| statusCode: 200, | ||
| headers: {}, | ||
| result: [] | ||
| }); | ||
| const distribution = new SemeruDistribution({ | ||
| @@ -109,6 +109,31 @@ describe('getAvailableVersions', () => { | ||
| const availableVersions = await distribution['getAvailableVersions'](); | ||
| expect(availableVersions).not.toBeNull(); | ||
| expect(availableVersions.length).toBe(manifestData.length * 2); | ||
| expect(spyHttpClient).toHaveBeenNthCalledWith(2, nextPageUrl); | ||
| }); | ||
| it('stops pagination after 1000 pages as a safeguard', async () => { | ||
| const nextPageUrl = | ||
| 'https://api.adoptopenjdk.net/v3/assets/version/%5B1.0,100.0%5D?page=2&page_size=20'; | ||
| spyHttpClient.mockReturnValue({ | ||
| statusCode: 200, | ||
| headers: {link: `<${nextPageUrl}>; rel="next"`}, | ||
| result: [{version_data: {semver: '17.0.1'}, binaries: []}] as any | ||
| }); | ||
johnoliver marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const distribution = new SemeruDistribution({ | ||
| version: '8', | ||
| architecture: 'x64', | ||
| packageType: 'jdk', | ||
| checkLatest: false | ||
| }); | ||
| await distribution['getAvailableVersions'](); | ||
| expect(spyHttpClient).toHaveBeenCalledTimes(1000); | ||
| expect(spyCoreWarning).toHaveBeenCalledWith( | ||
| expect.stringContaining('Reached pagination safeguard limit (1000 pages)') | ||
| ); | ||
| }); | ||
| it.each([ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,6 +12,7 @@ import * as core from '@actions/core'; | ||
| describe('getAvailableVersions', () => { | ||
| let spyHttpClient: jest.SpyInstance; | ||
| let spyCoreError: jest.SpyInstance; | ||
| let spyCoreWarning: jest.SpyInstance; | ||
| beforeEach(() => { | ||
| spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson'); | ||
| @@ -23,6 +24,8 @@ describe('getAvailableVersions', () => { | ||
| // Mock core.error to suppress error logs | ||
| spyCoreError = jest.spyOn(core, 'error'); | ||
| spyCoreError.mockImplementation(() => {}); | ||
| spyCoreWarning = jest.spyOn(core, 'warning'); | ||
| spyCoreWarning.mockImplementation(() => {}); | ||
| }); | ||
| afterEach(() => { | ||
| @@ -93,22 +96,19 @@ describe('getAvailableVersions', () => { | ||
| ); | ||
| it('load available versions', async () => { | ||
| const nextPageUrl = | ||
| 'https://api.adoptium.net/v3/assets/version/%5B1.0,100.0%5D?page=1&page_size=20'; | ||
| spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson'); | ||
| spyHttpClient | ||
| .mockReturnValueOnce({ | ||
| statusCode: 200, | ||
| headers: {}, | ||
| headers: {link: `<${nextPageUrl}>; rel="next"`}, | ||
| result: manifestData as any | ||
| }) | ||
| .mockReturnValueOnce({ | ||
| statusCode: 200, | ||
| headers: {}, | ||
| result: manifestData as any | ||
| }) | ||
| .mockReturnValueOnce({ | ||
| statusCode: 200, | ||
| headers: {}, | ||
| result: [] | ||
| }); | ||
| const distribution = new TemurinDistribution( | ||
| @@ -123,6 +123,34 @@ describe('getAvailableVersions', () => { | ||
| const availableVersions = await distribution['getAvailableVersions'](); | ||
| expect(availableVersions).not.toBeNull(); | ||
| expect(availableVersions.length).toBe(manifestData.length * 2); | ||
| expect(spyHttpClient).toHaveBeenNthCalledWith(2, nextPageUrl); | ||
| }); | ||
| it('stops pagination after 1000 pages as a safeguard', async () => { | ||
| const nextPageUrl = | ||
| 'https://api.adoptium.net/v3/assets/version/%5B1.0,100.0%5D?page=2&page_size=20'; | ||
| spyHttpClient.mockReturnValue({ | ||
| statusCode: 200, | ||
| headers: {link: `<${nextPageUrl}>; rel="next"`}, | ||
| result: [{version_data: {semver: '17.0.1'}, binaries: []}] as any | ||
| }); | ||
johnoliver marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const distribution = new TemurinDistribution( | ||
| { | ||
| version: '8', | ||
| architecture: 'x64', | ||
| packageType: 'jdk', | ||
| checkLatest: false | ||
| }, | ||
| TemurinImplementation.Hotspot | ||
| ); | ||
| await distribution['getAvailableVersions'](); | ||
| expect(spyHttpClient).toHaveBeenCalledTimes(1000); | ||
| expect(spyCoreWarning).toHaveBeenCalledWith( | ||
| expect.stringContaining('Reached pagination safeguard limit (1000 pages)') | ||
| ); | ||
| }); | ||
| it.each([ | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.