-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Paginate list clusters, add unit tests for ListClusters Signed-off-by: Judy Ng <[email protected]>
- Loading branch information
Showing
2 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import {ListClusters} from '../model' | ||
import {ClusterInfoSummary, ClusterStatus} from '../types/clusters' | ||
import {CloudFormationStackStatus} from '../types/base' | ||
|
||
const mockCluster1: ClusterInfoSummary = { | ||
clusterName: 'test-cluster-1', | ||
clusterStatus: ClusterStatus.CreateComplete, | ||
version: '3.8.0', | ||
cloudformationStackArn: 'arn', | ||
region: 'region', | ||
cloudformationStackStatus: CloudFormationStackStatus.CreateComplete, | ||
} | ||
|
||
const mockCluster2: ClusterInfoSummary = { | ||
clusterName: 'test-cluster-2', | ||
clusterStatus: ClusterStatus.CreateComplete, | ||
version: '3.8.0', | ||
cloudformationStackArn: 'arn', | ||
region: 'region', | ||
cloudformationStackStatus: CloudFormationStackStatus.CreateComplete, | ||
} | ||
|
||
const mockGet = jest.fn() | ||
|
||
jest.mock('axios', () => ({ | ||
create: () => ({ | ||
get: (...args: unknown[]) => mockGet(...args), | ||
}), | ||
})) | ||
|
||
describe('given a ListClusters command', () => { | ||
describe('when the clusters use pagination to be listed', () => { | ||
beforeEach(() => { | ||
const mockResponse1 = { | ||
nextToken: 'asdfghjkl', | ||
clusters: [mockCluster1], | ||
} | ||
|
||
const mockResponse2 = { | ||
clusters: [mockCluster2], | ||
} | ||
mockGet | ||
.mockResolvedValueOnce({data: mockResponse1}) | ||
.mockResolvedValueOnce({data: mockResponse2}) | ||
}) | ||
|
||
it('should return the list of all clusters', async () => { | ||
const data = await ListClusters() | ||
expect(data).toEqual([mockCluster1, mockCluster2]) | ||
}) | ||
}) | ||
|
||
describe('when the clusters are listed in one API call', () => { | ||
beforeEach(() => { | ||
const mockResponse1 = { | ||
clusters: [mockCluster1, mockCluster2], | ||
} | ||
mockGet.mockResolvedValueOnce({data: mockResponse1}) | ||
}) | ||
|
||
it('should return the list of all clusters', async () => { | ||
const data = await ListClusters() | ||
expect(data).toEqual([mockCluster1, mockCluster2]) | ||
}) | ||
}) | ||
|
||
describe('when there are no clusters', () => { | ||
beforeEach(() => { | ||
const mockResponse1 = { | ||
clusters: [], | ||
} | ||
mockGet.mockResolvedValueOnce({data: mockResponse1}) | ||
}) | ||
|
||
it('should return empty list', async () => { | ||
const data = await ListClusters() | ||
expect(data).toEqual([]) | ||
}) | ||
}) | ||
|
||
describe('when the list cluster fails', () => { | ||
let mockError: any | ||
|
||
beforeEach(() => { | ||
mockError = { | ||
response: { | ||
data: { | ||
message: 'some-error-messasge', | ||
}, | ||
}, | ||
} | ||
mockGet.mockRejectedValueOnce(mockError) | ||
}) | ||
|
||
it('should throw the error', async () => { | ||
try { | ||
await ListClusters() | ||
} catch (e) { | ||
expect(e).toEqual({ | ||
response: { | ||
data: { | ||
message: 'some-error-messasge', | ||
}, | ||
}, | ||
}) | ||
} | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
af3394f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can anyone provide a timeline on when a release will be created including this change? This issue is actively making the UI unusable for us, and we'd appreciate it if we could see a release as soon as possible
af3394f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been released as part of 2024.03.0