Skip to content

Commit

Permalink
chore: Add first test for GithubCustomResource (#5) (#30)
Browse files Browse the repository at this point in the history
We added a basic test during our [Hackergarten Meetup](https://www.meetup.com/de-DE/hackergarten-stuttgart/events/dvvlwsydcpbcb/).
  • Loading branch information
WtfJoke authored Nov 14, 2022
1 parent 76360ff commit a229eac
Show file tree
Hide file tree
Showing 2 changed files with 316 additions and 1 deletion.
265 changes: 265 additions & 0 deletions test/__snapshots__/github-custom-resource.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 51 additions & 1 deletion test/github-custom-resource.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
import { App, Stack } from "aws-cdk-lib";
import { Match, Template } from "aws-cdk-lib/assertions";
import { Secret } from "aws-cdk-lib/aws-secretsmanager";
import { Construct } from "constructs";
import { AuthOptions } from "../src/auth";
import { GithubCustomResource } from "../src/github-custom-resource";

describe("GithubCustomResource", () => {
it("", () => {});
it("Should match snapshot", () => {
// Given
const app = new App();
const stack = new GithubCustomResourceTestStack(app, "GithubTestStack");

// When
const template = Template.fromStack(stack);

// Then
expect(template).toMatchSnapshot();
});

it("Should contain GithubCustomResource with appAuth", () => {
// Given
const app = new App();
const stack = new GithubCustomResourceTestStack(app, "GithubTestStack");

// When
const template = Template.fromStack(stack);

// Then
template.hasResourceProperties("AWS::SecretsManager::Secret", { Description: "GithubAppAuthSecret" });
template.hasResourceProperties("AWS::CloudFormation::CustomResource", {
Auth: {
secret: {
Ref: Match.stringLikeRegexp("githubAuthSecret"),
},
strategy: "auth-app",
},
});
});
});

class GithubCustomResourceTestStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);

const secret = new Secret(this, "githubAuthSecret", {
description: "GithubAppAuthSecret",
});
new GithubCustomResource(this, "CR", {
authOptions: AuthOptions.appAuth(secret),
});
}
}

0 comments on commit a229eac

Please sign in to comment.