import { type TestCase, type DefaultCdkOptions } from '@aws-cdk/cloud-assembly-schema'; import { IntegTestSuite, LegacyIntegTestSuite } from './integ-test-suite'; import type { DeployOptions, DestroyOptions, ICdk, WatchEvents } from '../engines/cdk-interface'; import type { IntegTest } from './integration-tests'; import type { DestructiveChange } from '../workers/common'; /** * Options for creating a CDK Cloud Assembly */ export interface CdkTestAppOptions { readonly test: IntegTest; /** * The region where the test should be deployed */ readonly region?: string; /** * The AWS profile to use when invoking the CDK CLI * * @default - no profile is passed, the default profile is used */ readonly profile?: string; /** * Additional environment variables that will be available * to the CDK CLI * * @default - no additional environment variables */ readonly env?: { [name: string]: string; }; /** * Where we will write the output of the CDK CLI, including the cloud assembly and the snapshot * * Should be a string containing `{testName}`, will be used to generate a directory name in the same * directory as the test itself. * * @default 'cdk-integ.out.{testName}.snapshot' */ readonly outputDirectoryNameTemplate: string; /** * Instance of the CDK Toolkit Engine to use * * @default - based on `engine` option */ readonly cdk?: ICdk; /** * Show output from running integration tests * * @default false */ readonly showOutput?: boolean; /** * Use the indicated proxy * * @default - no proxy */ readonly proxy?: string; /** * Path to CA certificate to use when validating HTTPS requests * * @default - no additional CA bundle */ readonly caBundlePath?: string; /** * In unit test mode, we are using mocks for a lot of calls * * Don't delete directories, and don't do checks whether files actually exist; the * mocks will be there to produce the contents for files that are being read (although * they are not there to pretend to have files themselves). */ readonly TESTING_usingMocks?: boolean; /** * We will only read the legacy test information if the test actually produced an output directory. * * For historical reasons the tests have been written so that they will expect to read * legacy test information always. Force that behavior back for tests. */ readonly TESTING_forceReadLegacyTestSuite?: boolean; } /** * Whether to synthesize the actual snapshot with lookups enabled or not. * * If either `true` or `false`, we send context in or not while synthesizing, * and if the generated snapshot test definition requests a different value we * will synth again. * * For `dont-care`, we do send in the context but we never resynth. */ export type LegacyEnableLookups = true | false | 'dont-care'; /** * Class with some helper routines for running CDK snapshots and integration tests. * * A "golden snapshot" is the snapshot that is stored permanently in version * control, that new runs are compared against (stored in a directory named * `.snapshot`). * * This is as opposed to other snapshots, which can be generated for example * temporarily in a temporary directory, to compare agains the golden snapshot. */ export declare class CdkTestApp { private readonly options; private readonly testSpecificContext?; static forGoldenSnapshot(options: Omit): Promise; static forComparison(options: Omit): Promise; static forSpecificDirectory(options: CdkTestAppOptions): Promise; static forDeployment(options: Omit): Promise; private static create; /** * An instance of the CDK CLI */ private readonly cdk; readonly outputDirectory: string; /** * Default options to pass to the CDK CLI */ private readonly defaultArgs; /** * The profile to use for the CDK CLI calls */ readonly profile?: string; /** * Show output from the integ test run. */ private readonly showOutput; readonly test: IntegTest; synthReproCommand: string; _destructiveChanges?: DestructiveChange[]; private legacyContext?; private _testSuite?; private _legacyEnableLookups?; readonly appCommand: string; private hasValidRegion; private constructor(); /** * Configure the legacy enableLookups value to use when generating the actual snapshot. * * Must be set before using snapshot methods. */ configureLegacyEnableLookups(enableLookups: LegacyEnableLookups): void; hasOutput(): Promise; /** * Return the test cases inside the output */ testCases(): { [testName: string]: TestCase; }; /** * The test suite from the output */ get testSuite(): IntegTestSuite | LegacyIntegTestSuite; /** * If the snapshot already exists, load it */ loadExistingSuite(): Promise; synthForSnapshotComparison(enableLookupsGuess: LegacyEnableLookups): Promise; synthForGoldenSnapshot(destructiveChanges: DestructiveChange[], enableLookups: LegacyEnableLookups): Promise; synthForDeployment(): Promise; /** * For a given cloud assembly return a collection of all templates * that should be part of the snapshot and any required meta data. * * @param cloudAssemblyDir - The directory of the cloud assembly to look for snapshots * @param pickStacks - Pick only these stacks from the cloud assembly * @returns A SnapshotAssembly, the collection of all templates in this snapshot and required meta data */ snapshotAssembly(pickStacks?: string[]): SnapshotAssembly; private readAssembly; /** * Synth the actual application to the given directory, for purposes of generating/validating a snapshot * * `legacyEnableLookups` is to preserve historical behavior for a while: * traditionally, the application would only be seeded with context if * `enableLookups` was true, and this information would come from the test * definition. * * - Since the test definition comes from inside the app, this requires a * synth just to get the test definition, and then another synth to generate * the actual snapshot with the correct context, which is time consuming. * - Given that the context is fixed and fake, it could always have been passed. * * However, the snapshot contents themselves depend on the context flag, and changing * this behavior now invalidates all snapshots everywhere, which is annoying for upgrading. * * So we will use the behavior from the GOLDEN SNAPSHOT's test definition to * determine whether to pass the context, and if the new actual snapshot has a * different value for `enableLookups`, we will throw away the old snapshot and synth again. */ private synth; deploy(deployArgs: Omit): Promise; destroy(destroyArgs: Omit): Promise; watch(watchArgs: Omit, watchEvents: WatchEvents): Promise; private setReproCommand; private _loadLegacyTestSuite; cleanup(): void; /** * If there are any destructive changes to a stack then this will record * those in the manifest.json file */ private renderTraceData; /** * In cases where we do not want to retain the assets, * for example, if the assets are very large. * * Since it is possible to disable the update workflow for individual test * cases, this needs to first get a list of stacks that have the update workflow * disabled and then delete assets that relate to that stack. It does that * by reading the asset manifest for the stack and deleting the asset source */ private removeAssetsFromSnapshot; /** * Remove the asset cache (.cache/) files from the snapshot. * These are a cache of the asset zips, but we are fine with * re-zipping on deploy */ private removeAssetsCacheFromSnapshot; /** * Perform some cleanup steps after the snapshot is created * Anytime the snapshot needs to be modified after creation * the logic should live here. */ private cleanupGoldenSnapshot; getContext(forSnapshot: 'snapshot' | 'deployment'): Record; } export declare const DEFAULT_SYNTH_OPTIONS: { context: { "aws:cdk:availability-zones:fallback": string[]; 'availability-zones:account=12345678:region=test-region': string[]; 'ssm:account=12345678:parameterName=/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2:region=test-region': string; 'ssm:account=12345678:parameterName=/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2:region=test-region': string; 'ssm:account=12345678:parameterName=/aws/service/ecs/optimized-ami/amazon-linux/recommended:region=test-region': string; 'ami:account=12345678:filters.image-type.0=machine:filters.name.0=amzn-ami-vpc-nat-*:filters.state.0=available:owners.0=amazon:region=test-region': string; 'vpc-provider:account=12345678:filter.isDefault=true:region=test-region:returnAsymmetricSubnets=true': { vpcId: string; subnetGroups: { type: string; name: string; subnets: { subnetId: string; availabilityZone: string; routeTableId: string; }[]; }[]; }; }; env: { CDK_INTEG_ACCOUNT: string; CDK_INTEG_REGION: string; CDK_INTEG_HOSTED_ZONE_ID: string; CDK_INTEG_HOSTED_ZONE_NAME: string; CDK_INTEG_DOMAIN_NAME: string; CDK_INTEG_CERT_ARN: string; CDK_INTEG_SUBNET_ID: string; }; }; /** * Return the currently recommended flags for `aws-cdk-lib`. * * These have been built into the CLI at build time. If this ever gets changed * back to a dynamic load, remember that this source file may be bundled into * a JavaScript bundle, and `__dirname` might not point where you think it does. */ export declare function currentlyRecommendedAwsCdkLibFlags(): { "@aws-cdk/aws-signer:signingProfileNamePassedToCfn": boolean; "@aws-cdk/aws-ecs-patterns:secGroupsDisablesImplicitOpenListener": boolean; "@aws-cdk/aws-lambda:recognizeLayerVersion": boolean; "@aws-cdk/core:checkSecretUsage": boolean; "@aws-cdk/core:target-partitions": string[]; "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": boolean; "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": boolean; "@aws-cdk/aws-ecs:arnFormatIncludesClusterName": boolean; "@aws-cdk/aws-iam:minimizePolicies": boolean; "@aws-cdk/core:validateSnapshotRemovalPolicy": boolean; "@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": boolean; "@aws-cdk/aws-s3:createDefaultLoggingPolicy": boolean; "@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": boolean; "@aws-cdk/aws-apigateway:disableCloudWatchRole": boolean; "@aws-cdk/core:enablePartitionLiterals": boolean; "@aws-cdk/aws-events:eventsTargetQueueSameAccount": boolean; "@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": boolean; "@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": boolean; "@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": boolean; "@aws-cdk/aws-route53-patters:useCertificate": boolean; "@aws-cdk/customresources:installLatestAwsSdkDefault": boolean; "@aws-cdk/aws-rds:databaseProxyUniqueResourceName": boolean; "@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": boolean; "@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": boolean; "@aws-cdk/aws-ec2:launchTemplateDefaultUserData": boolean; "@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": boolean; "@aws-cdk/aws-redshift:columnId": boolean; "@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": boolean; "@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": boolean; "@aws-cdk/aws-apigateway:requestValidatorUniqueId": boolean; "@aws-cdk/aws-kms:aliasNameRef": boolean; "@aws-cdk/aws-kms:applyImportedAliasPermissionsToPrincipal": boolean; "@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": boolean; "@aws-cdk/core:includePrefixInUniqueNameGeneration": boolean; "@aws-cdk/aws-efs:denyAnonymousAccess": boolean; "@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": boolean; "@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": boolean; "@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": boolean; "@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": boolean; "@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": boolean; "@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": boolean; "@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": boolean; "@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": boolean; "@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": boolean; "@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": boolean; "@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": boolean; "@aws-cdk/aws-eks:nodegroupNameAttribute": boolean; "@aws-cdk/aws-eks:useNativeOidcProvider": boolean; "@aws-cdk/aws-ec2:ebsDefaultGp3Volume": boolean; "@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": boolean; "@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": boolean; "@aws-cdk/aws-s3:keepNotificationInImportedBucket": boolean; "@aws-cdk/core:explicitStackTags": boolean; "@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions": boolean; "@aws-cdk/aws-dynamodb:resourcePolicyPerReplica": boolean; "@aws-cdk/aws-ec2:ec2SumTImeoutEnabled": boolean; "@aws-cdk/aws-appsync:appSyncGraphQLAPIScopeLambdaPermission": boolean; "@aws-cdk/aws-rds:setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId": boolean; "@aws-cdk/core:cfnIncludeRejectComplexResourceUpdateCreatePolicyIntrinsics": boolean; "@aws-cdk/aws-lambda-nodejs:sdkV3ExcludeSmithyPackages": boolean; "@aws-cdk/aws-stepfunctions-tasks:fixRunEcsTaskPolicy": boolean; "@aws-cdk/aws-ec2:bastionHostUseAmazonLinux2023ByDefault": boolean; "@aws-cdk/aws-route53-targets:userPoolDomainNameMethodWithoutCustomResource": boolean; "@aws-cdk/aws-elasticloadbalancingV2:albDualstackWithoutPublicIpv4SecurityGroupRulesDefault": boolean; "@aws-cdk/aws-iam:oidcRejectUnauthorizedConnections": boolean; "@aws-cdk/core:enableAdditionalMetadataCollection": boolean; "@aws-cdk/aws-lambda:createNewPoliciesWithAddToRolePolicy": boolean; "@aws-cdk/aws-s3:setUniqueReplicationRoleName": boolean; "@aws-cdk/aws-events:requireEventBusPolicySid": boolean; "@aws-cdk/core:aspectPrioritiesMutating": boolean; "@aws-cdk/aws-dynamodb:retainTableReplica": boolean; "@aws-cdk/aws-stepfunctions:useDistributedMapResultWriterV2": boolean; "@aws-cdk/s3-notifications:addS3TrustKeyPolicyForSnsSubscriptions": boolean; "@aws-cdk/aws-ec2:requirePrivateSubnetsForEgressOnlyInternetGateway": boolean; "@aws-cdk/aws-s3:publicAccessBlockedByDefault": boolean; "@aws-cdk/aws-lambda:useCdkManagedLogGroup": boolean; "@aws-cdk/aws-elasticloadbalancingv2:networkLoadBalancerWithSecurityGroupByDefault": boolean; "@aws-cdk/aws-ecs-patterns:uniqueTargetGroupId": boolean; "@aws-cdk/aws-route53-patterns:useDistribution": boolean; "@aws-cdk/aws-cloudfront:defaultFunctionRuntimeV2_0": boolean; "@aws-cdk/aws-elasticloadbalancingv2:usePostQuantumTlsPolicy": boolean; "@aws-cdk/aws-batch:defaultToAL2023": boolean; "@aws-cdk/aws-eks:defaultToAL2023": boolean; "@aws-cdk/core:annotationsInValidationReport": boolean; "@aws-cdk/core:defaultCrossStackReferences": string; "@aws-cdk/core:validateAgainstDefaultRules": boolean; "@aws-cdk/aws-ecs:removeEmptyLoadBalancers": boolean; }; export interface SnapshotAssembly { /** * Map of stacks that are part of this assembly */ [stackName: string]: { /** * All templates for this stack, including nested stacks */ templates: { [templateId: string]: any; }; /** * List of asset Ids that are used by this assembly */ assets: string[]; }; } /** * Default options to pass to the CDK CLI */ export declare const DEFAULT_ARGS: DefaultCdkOptions; //# sourceMappingURL=cdk-test-app.d.ts.map