-
Notifications
You must be signed in to change notification settings - Fork 29
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
chore: Add snapshot test for TypeScript step function stack #327
Conversation
export class ExampleStack extends Stack { | ||
constructor(scope: Construct, id: string, props?: StackProps) { | ||
super(scope, id, props); | ||
|
||
console.log("Creating Hello World TypeScript stack"); | ||
|
||
/* Set up the child state machine */ | ||
|
||
const passState = new sfn.Pass(this, "PassState"); | ||
const waitState = new sfn.Wait(this, "WaitState", { time: sfn.WaitTime.duration(Duration.seconds(1)) }); | ||
const successState = new sfn.Succeed(this, "SuccessState"); | ||
|
||
const childStateMachine = new sfn.StateMachine(this, "CdkTypeScriptTestChildStateMachine", { | ||
definitionBody: sfn.DefinitionBody.fromChainable(passState.next(waitState).next(successState)), | ||
}); | ||
|
||
/* Set up the parent state machine */ | ||
|
||
const invokeChildStateMachineTask = new tasks.StepFunctionsStartExecution(this, "InvokeChildStateMachineTask", { | ||
stateMachine: childStateMachine, | ||
input: sfn.TaskInput.fromObject( | ||
DatadogStepFunctions.buildStepFunctionTaskPayloadToMergeTraces({ "custom-key": "custom-value" }), | ||
), | ||
}); | ||
|
||
const helloLambdaFunction = new lambda.Function(this, "hello-python", { | ||
runtime: lambda.Runtime.PYTHON_3_12, | ||
handler: "index.handler", | ||
code: lambda.Code.fromInline(` | ||
def handler(event, context): | ||
return "Hello, world!" | ||
`), | ||
}); | ||
|
||
const lambdaTask = new tasks.LambdaInvoke(this, "MyLambdaTask", { | ||
lambdaFunction: helloLambdaFunction, | ||
payload: sfn.TaskInput.fromObject(DatadogStepFunctions.buildLambdaPayloadToMergeTraces()), | ||
}); | ||
|
||
const parentStateMachine = new sfn.StateMachine(this, "CdkTypeScriptTestStateMachine", { | ||
definitionBody: sfn.DefinitionBody.fromChainable(lambdaTask.next(invokeChildStateMachineTask)), | ||
}); | ||
|
||
/* Instrument the lambda functions and the state machines */ | ||
|
||
console.log("Instrumenting Step Functions in TypeScript stack with Datadog"); | ||
|
||
const datadogSfn = new DatadogStepFunctions(this, "DatadogSfn", { | ||
env: "dev", | ||
service: "cdk-test-service", | ||
version: "1.0.0", | ||
forwarderArn: process.env.DD_FORWARDER_ARN, | ||
tags: "custom-tag-1:tag-value-1,custom-tag-2:tag-value-2", | ||
}); | ||
datadogSfn.addStateMachines([childStateMachine, parentStateMachine]); | ||
|
||
const datadogLambda = new DatadogLambda(this, "DatadogLambda", { | ||
pythonLayerVersion: 101, | ||
extensionLayerVersion: 65, | ||
addLayers: true, | ||
apiKey: process.env.DD_API_KEY, | ||
enableDatadogTracing: true, | ||
enableDatadogASM: true, | ||
flushMetricsToLogs: true, | ||
site: "datadoghq.com", | ||
env: "dev", | ||
service: "cdk-test-service", | ||
version: "1.0.0", | ||
}); | ||
datadogLambda.addLambdaFunctions([helloLambdaFunction]); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚪ Code Quality Violation
This class is unnecessary (...read more)
This rule advises against the unnecessary use of classes that contain only static members, or nothing. In JavaScript, classes are primarily used for object-oriented programming, where each instance of a class has its own state and behavior. Static members, on the other hand, belong to the class itself and not to any instance of the class.
When a class contains only static members, it does not make use of JavaScript's object-oriented capabilities, and it can be more difficult to understand, test, and maintain than necessary. In order to avoid this issue, consider using regular functions and variables instead of static class members. This makes your code easier to understand and maintain, and it allows you to make better use of JavaScript's features.
const app = new App(); | ||
const env = { account: "601427279990", region: "sa-east-1" }; | ||
const stack = new ExampleStack(app, "step-function-stack", { env: env }); | ||
console.log("Stack name: " + stack.stackName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
/* Instrument the lambda functions and the state machines */ | ||
|
||
console.log("Instrumenting Step Functions in TypeScript stack with Datadog"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constructor(scope: Construct, id: string, props?: StackProps) { | ||
super(scope, id, props); | ||
|
||
console.log("Creating Hello World TypeScript stack"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dcb1f10
to
3c9612d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
b58f77d
to
44dabdc
Compare
3c9612d
to
a38a4f3
Compare
/merge |
Devflow running:
|
What does this PR do?
Add a snapshot test for a TypeScript step function stack to ensure future changes don't unintentionally change the synthesized CloudFormation template.
Motivation
Testing Guidelines
Additional Notes
Types of Changes
Check all that apply