I'm having trouble finding the right reference because when I search, most of what I want is how to test constructs themselves. What I'm searching for is how to run my application tests, not the infrastructure/construct tests. Is that a testing stage that I should add?
The tests that I'm referring to are the ones normally run by running npm test (or rake test in the Ruby/Rails world, or ./manage.py test in the Django world). Whether you call them integration or unit tests is debatable. They don't necessarily run a whole web server, but they do use the database. In my case these tests might use DynamoDB, SQS, and other services. The functions being tested would be a mixed of Lambda functions and their internal units. I wouldn't expect to run them in a Lambda environment. I would expect to run this tests locally on my machine constantly as I develop. These would be the tests that are run on a pull requests from GitHub as one of the things that block or allow the pull request to be merged. This is the standard Heroku CI/CD model in case you are familiar with that.
For reference, my current pipeline stack looks like this (it started from https://cdkworkshop.com/ and I'm evolving it, Example4Be is my application):
import * as cdk from "aws-cdk-lib"
import * as secretsmanager from "aws-cdk-lib/aws-secretsmanager"
import {Construct} from "constructs"
import {Example4BeDeployStage} from "./example4-be-deploy-stage"
import {CodeBuildStep, CodePipeline, CodePipelineSource} from "aws-cdk-lib/pipelines"
export class PipelineStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props)
const githubSecretId = "github-flexpointtech-token"
const secret = new secretsmanager.Secret(this, githubSecretId)
// The basic pipeline declaration. This sets the initial structure
// of our pipeline
const pipeline = new CodePipeline(this, "Example4BePipeline", {
synth: new CodeBuildStep("Synth", {
input: CodePipelineSource.gitHub("flexpointtech/example4-be", "main", {
authentication: cdk.SecretValue.secretsManager(githubSecretId)
}),
installCommands: [
"npm install -g aws-cdk"
],
commands: [
"npm ci",
"npm run build",
"npx cdk synth"
]
}
)
})
pipeline.node.addDependency(secret)
const deploy = new Example4BeDeployStage(this, "Deploy")
const deployStage = pipeline.addStage(deploy)
deployStage.addPost(
new CodeBuildStep("VerifyViewerEndpoint", {
envFromCfnOutputs: {
ENDPOINT_URL: deploy.hcViewerUrl
},
commands: [
"curl -Ssf $ENDPOINT_URL"
]
}),
new CodeBuildStep("VerifyAPIGatewayEndpoint", {
envFromCfnOutputs: {
ENDPOINT_URL: deploy.hcEndpoint
},
commands: [
"curl -Ssf $ENDPOINT_URL",
"curl -Ssf $ENDPOINT_URL/hello",
"curl -Ssf $ENDPOINT_URL/test"
]
})
)
}
}