-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[Multi-bucket] Update options to include bucket #13574
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
Changes from all commits
61b6bd1
26cea41
98ce450
469e7b5
6259cdc
569a1ec
385e3f5
0cbeda0
b0b53e3
773e90b
6a26594
0445ab3
bf31d74
38fb333
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import { | |
ItemWithPath, | ||
} from '../../../../src/providers/s3/types/outputs'; | ||
import './testUtils'; | ||
import { BucketInfo } from '../../../../src/providers/s3/types/options'; | ||
|
||
jest.mock('../../../../src/providers/s3/utils/client'); | ||
jest.mock('../../../../src/providers/s3/utils'); | ||
|
@@ -62,7 +63,7 @@ const mockDownloadResultBase = { | |
const mockFetchAuthSession = Amplify.Auth.fetchAuthSession as jest.Mock; | ||
const mockCreateDownloadTask = createDownloadTask as jest.Mock; | ||
const mockValidateStorageInput = validateStorageOperationInput as jest.Mock; | ||
const mockGetConfig = Amplify.getConfig as jest.Mock; | ||
const mockGetConfig = jest.mocked(Amplify.getConfig); | ||
|
||
describe('downloadData with key', () => { | ||
beforeAll(() => { | ||
|
@@ -75,6 +76,7 @@ describe('downloadData with key', () => { | |
S3: { | ||
bucket, | ||
region, | ||
buckets: { 'default-bucket': { bucketName: bucket, region } }, | ||
}, | ||
}, | ||
}); | ||
|
@@ -220,6 +222,70 @@ describe('downloadData with key', () => { | |
}), | ||
); | ||
}); | ||
|
||
describe('bucket passed in options', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding additional tests. One thought here is that the bucket info overriding is carried by the function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So couple of pointers here, i think what called out makes sense.
That said, with next PR on copy API if this still stays here i can add in test specific to that function to check high level. But i think it is still beneficial per API level as well. wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a big deal, but is there a way to compose this such that the same logic can be re-used between suites? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah i thought about it but we kinda do this in all test suites. Also, i see value in testing this API level like we are doing other places. let me take another look at this. All of these are testing their input on actual s3 call , so i think even if we compose we still need to pass that part in |
||
it('should override bucket in getObject call when bucket is object', async () => { | ||
(getObject as jest.Mock).mockResolvedValueOnce({ Body: 'body' }); | ||
const abortController = new AbortController(); | ||
const bucketInfo: BucketInfo = { | ||
bucketName: 'bucket-1', | ||
region: 'region-1', | ||
}; | ||
|
||
downloadData({ | ||
key: inputKey, | ||
options: { | ||
bucket: bucketInfo, | ||
}, | ||
}); | ||
|
||
const { job } = mockCreateDownloadTask.mock.calls[0][0]; | ||
await job(); | ||
|
||
expect(getObject).toHaveBeenCalledTimes(1); | ||
await expect(getObject).toBeLastCalledWithConfigAndInput( | ||
{ | ||
credentials, | ||
region: bucketInfo.region, | ||
abortSignal: abortController.signal, | ||
userAgentValue: expect.any(String), | ||
}, | ||
{ | ||
Bucket: bucketInfo.bucketName, | ||
Key: `public/${inputKey}`, | ||
}, | ||
); | ||
}); | ||
|
||
it('should override bucket in getObject call when bucket is string', async () => { | ||
(getObject as jest.Mock).mockResolvedValueOnce({ Body: 'body' }); | ||
const abortController = new AbortController(); | ||
|
||
downloadData({ | ||
key: inputKey, | ||
options: { | ||
bucket: 'default-bucket', | ||
}, | ||
}); | ||
|
||
const { job } = mockCreateDownloadTask.mock.calls[0][0]; | ||
await job(); | ||
|
||
expect(getObject).toHaveBeenCalledTimes(1); | ||
await expect(getObject).toBeLastCalledWithConfigAndInput( | ||
{ | ||
credentials, | ||
region, | ||
abortSignal: abortController.signal, | ||
userAgentValue: expect.any(String), | ||
}, | ||
{ | ||
Bucket: bucket, | ||
Key: `public/${inputKey}`, | ||
}, | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('downloadData with path', () => { | ||
|
@@ -233,6 +299,7 @@ describe('downloadData with path', () => { | |
S3: { | ||
bucket, | ||
region, | ||
buckets: { 'default-bucket': { bucketName: bucket, region } }, | ||
}, | ||
}, | ||
}); | ||
|
@@ -366,4 +433,68 @@ describe('downloadData with path', () => { | |
}), | ||
); | ||
}); | ||
|
||
describe('bucket passed in options', () => { | ||
it('should override bucket in getObject call when bucket is object', async () => { | ||
(getObject as jest.Mock).mockResolvedValueOnce({ Body: 'body' }); | ||
const abortController = new AbortController(); | ||
const bucketInfo: BucketInfo = { | ||
bucketName: 'bucket-1', | ||
region: 'region-1', | ||
}; | ||
|
||
downloadData({ | ||
path: inputPath, | ||
options: { | ||
bucket: bucketInfo, | ||
}, | ||
}); | ||
|
||
const { job } = mockCreateDownloadTask.mock.calls[0][0]; | ||
await job(); | ||
|
||
expect(getObject).toHaveBeenCalledTimes(1); | ||
await expect(getObject).toBeLastCalledWithConfigAndInput( | ||
{ | ||
credentials, | ||
region: bucketInfo.region, | ||
abortSignal: abortController.signal, | ||
userAgentValue: expect.any(String), | ||
}, | ||
{ | ||
Bucket: bucketInfo.bucketName, | ||
Key: inputPath, | ||
}, | ||
); | ||
}); | ||
|
||
it('should override bucket in getObject call when bucket is string', async () => { | ||
(getObject as jest.Mock).mockResolvedValueOnce({ Body: 'body' }); | ||
const abortController = new AbortController(); | ||
|
||
downloadData({ | ||
path: inputPath, | ||
options: { | ||
bucket: 'default-bucket', | ||
}, | ||
}); | ||
|
||
const { job } = mockCreateDownloadTask.mock.calls[0][0]; | ||
await job(); | ||
|
||
expect(getObject).toHaveBeenCalledTimes(1); | ||
await expect(getObject).toBeLastCalledWithConfigAndInput( | ||
{ | ||
credentials, | ||
region, | ||
abortSignal: abortController.signal, | ||
userAgentValue: expect.any(String), | ||
}, | ||
{ | ||
Bucket: bucket, | ||
Key: inputPath, | ||
}, | ||
); | ||
}); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.