-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a GitHub Action to verify the aws-testing-cdk project. It runs t…
…he linter and tests. Adds a unit test for this project. Correct the formatting to pass the linter. Signed-off-by: David Venable <[email protected]>
- Loading branch information
Showing
6 changed files
with
134 additions
and
24 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,34 @@ | ||
name: Testing Resources CDK App Check | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- 'testing/aws-testing-cdk/**' | ||
pull_request: | ||
paths: | ||
- 'testing/aws-testing-cdk/**' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
verify: | ||
runs-on: ubuntu-latest | ||
|
||
defaults: | ||
run: | ||
working-directory: ./testing/aws-testing-cdk | ||
steps: | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '18' | ||
|
||
- name: Checkout Data Prepper | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install NPM Dependencies | ||
run: npm install | ||
- name: Test | ||
run: npm run test | ||
- name: Lint | ||
run: npm run lint |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import {Duration, RemovalPolicy, Stack, StackProps} from 'aws-cdk-lib'; | ||
import {Construct} from 'constructs'; | ||
import {Role} from 'aws-cdk-lib/aws-iam'; | ||
import {Bucket} from 'aws-cdk-lib/aws-s3'; | ||
|
||
export interface S3SinkStackProps extends StackProps { | ||
readonly testingRole: Role; | ||
} | ||
|
||
/** | ||
* CDK stack that creates a common KMS key. | ||
*/ | ||
export class S3SinkStack extends Stack { | ||
readonly bucket: Bucket; | ||
|
||
constructor(scope: Construct, id: string, props: S3SinkStackProps) { | ||
super(scope, id, props); | ||
|
||
new Bucket(this, 'MyBucket', { | ||
removalPolicy: RemovalPolicy.DESTROY, | ||
lifecycleRules: [ | ||
{ | ||
expiration: Duration.days(10) | ||
} | ||
] | ||
}); | ||
|
||
this.bucket.grantWrite(props.testingRole) | ||
} | ||
} | ||
|
40 changes: 40 additions & 0 deletions
40
testing/aws-testing-cdk/test/common/GitHubAccessStack.test.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,40 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import {App} from 'aws-cdk-lib'; | ||
import {Template} from 'aws-cdk-lib/assertions'; | ||
import {GitHubAccessStack} from '../../lib/common/GitHubAccessStack'; | ||
|
||
test('Creates OpenId Connect provider for GitHub', () => { | ||
const app = new App(); | ||
|
||
const stackUnderTest = new GitHubAccessStack(app, 'TestStack'); | ||
|
||
const template = Template.fromStack(stackUnderTest); | ||
|
||
template.hasResourceProperties('Custom::AWSCDKOpenIdConnectProvider', { | ||
Url: 'https://token.actions.githubusercontent.com', | ||
ClientIDList: ['sts.amazonaws.com'] | ||
}); | ||
|
||
template.hasResourceProperties('AWS::IAM::Role', { | ||
RoleName: 'GitHubActionsTesting', | ||
}); | ||
}); | ||
|
||
test('Uses existing OpenId Connect provider for GitHub when gitHubOidcProviderExists', () => { | ||
const app = new App(); | ||
app.node.setContext('gitHubOidcProviderExists', true) | ||
|
||
const stackUnderTest = new GitHubAccessStack(app, 'TestStack'); | ||
|
||
const template = Template.fromStack(stackUnderTest); | ||
|
||
template.resourceCountIs('Custom::AWSCDKOpenIdConnectProvider', 0) | ||
|
||
template.hasResourceProperties('AWS::IAM::Role', { | ||
RoleName: 'GitHubActionsTesting', | ||
}); | ||
}); |