Skip to content

Commit a32674a

Browse files
chore(migrate): add go and update tests (#27226)
---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a2a4f68 commit a32674a

File tree

9 files changed

+117
-12
lines changed

9 files changed

+117
-12
lines changed

packages/@aws-cdk/cli-lib-alpha/THIRD_PARTY_LICENSES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
461461

462462
----------------
463463

464-
** cdk-from-cfn@0.11.0 - https://www.npmjs.com/package/cdk-from-cfn/v/0.11.0 | MIT OR Apache-2.0
464+
** cdk-from-cfn@0.17.0 - https://www.npmjs.com/package/cdk-from-cfn/v/0.17.0 | MIT OR Apache-2.0
465465

466466
----------------
467467

packages/aws-cdk/THIRD_PARTY_LICENSES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
461461

462462
----------------
463463

464-
** cdk-from-cfn@0.11.0 - https://www.npmjs.com/package/cdk-from-cfn/v/0.11.0 | MIT OR Apache-2.0
464+
** cdk-from-cfn@0.17.0 - https://www.npmjs.com/package/cdk-from-cfn/v/0.17.0 | MIT OR Apache-2.0
465465

466466
----------------
467467

packages/aws-cdk/lib/commands/migrate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export async function generateCdkApp(stackName: string, stack: string, language:
5353
case 'csharp':
5454
stackFileName = `${resolvedOutputPath}/src/${camelCase(formattedStackName, { pascalCase: true })}/${camelCase(formattedStackName, { pascalCase: true })}Stack.cs`;
5555
break;
56-
// TODO: Add Go support
56+
case 'go':
57+
stackFileName = `${resolvedOutputPath}/${formattedStackName}.go`;
58+
break;
5759
default:
5860
throw new Error(`${language} is not supported by CDK Migrate. Please choose from: ${MIGRATE_SUPPORTED_LANGUAGES.join(', ')}`);
5961
}

packages/aws-cdk/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"aws-cdk-lib": "0.0.0",
8383
"aws-sdk-mock": "5.6.0",
8484
"axios": "^0.27.2",
85-
"cdk-from-cfn": "^0.11.0",
85+
"cdk-from-cfn": "^0.17.0",
8686
"constructs": "^10.0.0",
8787
"fast-check": "^3.12.1",
8888
"jest": "^29.6.4",
@@ -105,7 +105,7 @@
105105
"aws-sdk": "^2.1451.0",
106106
"camelcase": "^6.3.0",
107107
"cdk-assets": "0.0.0",
108-
"cdk-from-cfn": "^0.11.0",
108+
"cdk-from-cfn": "^0.17.0",
109109
"chalk": "^4",
110110
"chokidar": "^3.5.3",
111111
"decamelize": "^5.0.1",

packages/aws-cdk/test/commands/migrate.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ describe('Migrate Function Tests', () => {
9898
expect(stack).toEqual(fs.readFileSync(path.join(...stackPath, 'S3Stack.cs'), 'utf8'));
9999
});
100100

101+
// TODO: fix with actual go template
102+
test('generateStack generates the expected stack string when called for go', () => {
103+
const stack = generateStack(validTemplate, 'GoodGo', 'go');
104+
expect(stack).toEqual(fs.readFileSync(path.join(...stackPath, 's3.go'), 'utf8'));
105+
});
106+
101107
test('generateStack throws error when called for other language', () => {
102108
expect(() => generateStack(validTemplate, 'BadBadBad', 'php')).toThrowError('stack generation failed due to error \'unreachable\'');
103109
});
@@ -178,6 +184,16 @@ describe('Migrate Function Tests', () => {
178184
expect(replacedStack).toEqual(fs.readFileSync(path.join(...stackPath, 'S3Stack.cs')));
179185
});
180186

187+
cliTest('generatedCdkApp generates the expected cdk app when called for go', async (workDir) => {
188+
const stack = generateStack(validTemplate, 'GoodGo', 'go');
189+
await generateCdkApp('GoodGo', stack, 'go', workDir);
190+
191+
expect(fs.pathExists(path.join(workDir, 's3.go'))).toBeTruthy();
192+
const app = fs.readFileSync(path.join(workDir, 'GoodGo', 'good_go.go'), 'utf8').split('\n');
193+
expect(app.map(line => line.match(/func NewGoodGoStack\(scope constructs.Construct, id string, props GoodGoStackProps\) \*GoodGoStack \{/)).filter(line => line).length).toEqual(1);
194+
expect(app.map(line => line.match(/ NewGoodGoStack\(app, "GoodGo", &GoodGoStackProps\{/)));
195+
});
196+
181197
cliTest('generatedCdkApp generates a zip file when --compress is used', async (workDir) => {
182198
const stack = generateStack(validTemplate, 'GoodTypeScript', 'typescript');
183199
await generateCdkApp('GoodTypeScript', stack, 'typescript', workDir, true);

packages/aws-cdk/test/commands/test-resources/stacks/S3Stack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.acme.test.simple;
1+
package com.myorg;
22

33
import software.constructs.Construct;
44

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package main
2+
3+
import (
4+
cdk "github.com/aws/aws-cdk-go/awscdk/v2"
5+
s3 "github.com/aws/aws-cdk-go/awscdk/v2/awss3"
6+
"github.com/aws/constructs-go/constructs/v10"
7+
"github.com/aws/jsii-runtime-go"
8+
)
9+
10+
type GoodGoStackProps struct {
11+
cdk.StackProps
12+
}
13+
14+
/// AWS CloudFormation Sample Template S3_Website_Bucket_With_Retain_On_Delete: Sample template showing how to create a publicly accessible S3 bucket configured for website access with a deletion policy of retain on delete.
15+
type GoodGoStack struct {
16+
cdk.Stack
17+
/// URL for website hosted on S3
18+
WebsiteUrl interface{} // TODO: fix to appropriate type
19+
/// Name of S3 bucket to hold website content
20+
S3BucketSecureUrl interface{} // TODO: fix to appropriate type
21+
}
22+
23+
func NewGoodGoStack(scope constructs.Construct, id string, props GoodGoStackProps) *GoodGoStack {
24+
stack := cdk.NewStack(scope, &id, &props.StackProps)
25+
26+
s3Bucket := s3.NewCfnBucket(
27+
stack,
28+
jsii.String("S3Bucket"),
29+
&s3.CfnBucketProps{
30+
AccessControl: jsii.String("PublicRead"),
31+
WebsiteConfiguration: &WebsiteConfiguration/* FIXME */{
32+
IndexDocument: jsii.String("index.html"),
33+
ErrorDocument: jsii.String("error.html"),
34+
},
35+
},
36+
)
37+
38+
return &GoodGoStack{
39+
Stack: stack,
40+
WebsiteUrl: s3Bucket.AttrWebsiteUrl(),
41+
S3BucketSecureUrl: cdk.Fn_Join(jsii.String(""), &[]*string{
42+
jsii.String("https://"),
43+
s3Bucket.AttrDomainName(),
44+
}),
45+
}
46+
}
47+
48+
func main() {
49+
defer jsii.Close()
50+
51+
app := awscdk.NewApp(nil)
52+
53+
NewGoodGoStack(app, "GoodGo", &GoodGoStackProps{
54+
awscdk.StackProps{
55+
Env: env(),
56+
},
57+
})
58+
59+
app.Synth(nil)
60+
}
61+
62+
// env determines the AWS environment (account+region) in which our stack is to
63+
// be deployed. For more information see: https://docs.aws.amazon.com/cdk/latest/guide/environments.html
64+
func env() *awscdk.Environment {
65+
// If unspecified, this stack will be "environment-agnostic".
66+
// Account/Region-dependent features and context lookups will not work, but a
67+
// single synthesized template can be deployed anywhere.
68+
//---------------------------------------------------------------------------
69+
return nil
70+
71+
// Uncomment if you know exactly what account and region you want to deploy
72+
// the stack to. This is the recommendation for production stacks.
73+
//---------------------------------------------------------------------------
74+
// return &awscdk.Environment{
75+
// Account: jsii.String("123456789012"),
76+
// Region: jsii.String("us-east-1"),
77+
// }
78+
79+
// Uncomment to specialize this stack for the AWS Account and Region that are
80+
// implied by the current CLI configuration. This is recommended for dev
81+
// stacks.
82+
//---------------------------------------------------------------------------
83+
// return &awscdk.Environment{
84+
// Account: jsii.String(os.Getenv("CDK_DEFAULT_ACCOUNT")),
85+
// Region: jsii.String(os.Getenv("CDK_DEFAULT_REGION")),
86+
// }
87+
}

packages/aws-cdk/test/commands/test-resources/stacks/s3_stack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
3030
s3Bucket.cfnOptions.deletionPolicy = cdk.CfnDeletionPolicy.RETAIN
3131

3232
# Outputs
33-
self.website_u_r_l = s3Bucket.attrwebsiteUrl
33+
self.website_u_r_l = s3Bucket.attr_website_u_r_l
3434
cdk.CfnOutput(self, 'WebsiteURL',
3535
description = 'URL for website hosted on S3',
3636
value = self.website_u_r_l,
3737
)
3838
self.s3_bucket_secure_u_r_l = [
3939
'https://',
40-
s3Bucket.attrdomainName,
40+
s3Bucket.attr_domain_name,
4141
].join('')
4242
cdk.CfnOutput(self, 'S3BucketSecureURL',
4343
description = 'Name of S3 bucket to hold website content',

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5841,10 +5841,10 @@ [email protected], case@^1.6.3:
58415841
resolved "https://registry.npmjs.org/case/-/case-1.6.3.tgz#0a4386e3e9825351ca2e6216c60467ff5f1ea1c9"
58425842
integrity sha512-mzDSXIPaFwVDvZAHqZ9VlbyF4yyXRuX6IvB06WvPYkqJVO24kX1PPhv9bfpKNFZyxYFmmgo03HUiD8iklmJYRQ==
58435843

5844-
cdk-from-cfn@^0.11.0:
5845-
version "0.11.0"
5846-
resolved "https://registry.npmjs.org/cdk-from-cfn/-/cdk-from-cfn-0.11.0.tgz#b294dcc886323195b1b891161cda843170eba535"
5847-
integrity sha512-Pk0Sfp0LT0XXTqAf+QRLwvcY2x/2bvm6JGwV6ABLvdJAFAQa1XsGaELkSRZqz1C2iB5vp8dVw0EC0v1x3c5bHQ==
5844+
cdk-from-cfn@^0.17.0:
5845+
version "0.17.0"
5846+
resolved "https://registry.npmjs.org/cdk-from-cfn/-/cdk-from-cfn-0.17.0.tgz#46f77dc1141c21ee99255cdda59a8a2d2d428755"
5847+
integrity sha512-7sJnvEfnlFhYdIih4XZfIpUFiIy0ogdLXHk8BZEaWdG1tSpUOV9HTmk5IvZJr6YfF1j1D21kvrGLZYZNsRr7HA==
58485848

58495849
cdk-generate-synthetic-examples@^0.1.291:
58505850
version "0.1.291"

0 commit comments

Comments
 (0)