-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add integ test to test too many sources
- Loading branch information
Showing
3 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
...sting/framework-integ/test/aws-s3-deployment/test/integ.bucket-deployment-big-response.ts
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,70 @@ | ||
import * as os from 'os'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as s3 from 'aws-cdk-lib/aws-s3'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
import * as integ from '@aws-cdk/integ-tests-alpha'; | ||
import { Construct } from 'constructs'; | ||
import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment'; | ||
import { CfnOutput, Fn } from 'aws-cdk-lib'; | ||
import { ExpectedResult } from '@aws-cdk/integ-tests-alpha'; | ||
|
||
const numFiles = 50; | ||
|
||
class TestBucketDeployment extends cdk.Stack { | ||
public readonly destinationBucket: s3.IBucket; | ||
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props); | ||
|
||
this.destinationBucket = new s3.Bucket(this, 'Destination', { | ||
removalPolicy: cdk.RemovalPolicy.DESTROY, | ||
autoDeleteObjects: true, // needed for integration test cleanup | ||
}); | ||
|
||
const sources = []; | ||
for (let i = 0; i < numFiles; i++) { | ||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'tmpcdk')); | ||
fs.mkdirSync(tempDir, { recursive: true }); | ||
const fileName = `${i+1}.txt`; | ||
const filePath = path.join(tempDir, fileName); | ||
fs.writeFileSync(filePath, `This is file number ${i + 1}`); | ||
sources.push(s3deploy.Source.asset(tempDir)); | ||
} | ||
|
||
const deploymentBucket = new s3deploy.BucketDeployment(this, 'DeployMe', { | ||
sources: sources, | ||
destinationBucket: this.destinationBucket, | ||
memoryLimit: 2048, | ||
retainOnDelete: false, // default is true, which will block the integration test cleanup | ||
outputObjectKeys: false, | ||
}); | ||
|
||
new CfnOutput(this, 'customResourceData', { | ||
value: Fn.join(',', deploymentBucket.objectKeys), | ||
}); | ||
} | ||
} | ||
|
||
const app = new cdk.App(); | ||
const testCase = new TestBucketDeployment(app, 'test-bucket-deployments-too-many-sources'); | ||
|
||
// Assert that DeployMeWithoutExtractingFilesOnDestination deploys a zip file to bucket4 | ||
const integTest = new integ.IntegTest(app, 'integ-test-bucket-deployments', { | ||
testCases: [testCase], | ||
diffAssets: true, | ||
}); | ||
|
||
for (let i = 0; i < numFiles; i++) { | ||
const apiCall = integTest.assertions.awsApiCall('S3', 'getObject', { | ||
Bucket: testCase.destinationBucket.bucketName, | ||
Key: `${i+1}.txt`, | ||
}); | ||
apiCall.provider.addToRolePolicy({ | ||
Effect: 'Allow', | ||
Action: ['s3:GetObject', 's3:ListBucket'], | ||
Resource: ['*'], | ||
}); | ||
apiCall.assertAtPath('Body', ExpectedResult.stringLikeRegexp(`This is file number ${i + 1}`)); | ||
} | ||
|
||
app.synth(); |
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
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