Skip to content

Commit 7be8bcd

Browse files
vicheeynkomonen-amazon
authored andcommitted
test(lambda): add integration for Serverless Land (aws#6711)
## Problem No test coverage for Serverless Land Integration workflow. ## Solution Add integration test for Serverless Land Integration workflow. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 403a8de commit 7be8bcd

File tree

2 files changed

+142
-3
lines changed

2 files changed

+142
-3
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import assert from 'assert'
7+
import * as vscode from 'vscode'
8+
import path from 'path'
9+
import { PrompterTester } from '../../../test/shared/wizards/prompterTester'
10+
import { describe } from 'mocha'
11+
import { ProjectMetadata } from '../../../awsService/appBuilder/serverlessLand/metadataManager'
12+
import fs from '../../../shared/fs/fs'
13+
import { AppBuilderRootNode } from '../../../awsService/appBuilder/explorer/nodes/rootNode'
14+
import * as sinon from 'sinon'
15+
import { AppNode } from '../../../awsService/appBuilder/explorer/nodes/appNode'
16+
import { ResourceNode } from '../../../awsService/appBuilder/explorer/nodes/resourceNode'
17+
import { getTestWindow } from '../../../test/shared/vscode/window'
18+
19+
describe('Serverless Land Integration', async () => {
20+
const metadataPath = path.resolve(
21+
__dirname,
22+
'../../../../../src/awsService/appBuilder/serverlessLand/metadata.json'
23+
)
24+
const metadataContent = await fs.readFileText(metadataPath)
25+
const parseMetadata = JSON.parse(metadataContent) as ProjectMetadata
26+
const workspaceFolder = vscode.workspace.workspaceFolders![0]
27+
const projectFolder = 'my-project-from-Serverless-Land'
28+
let rootNode: sinon.SinonSpiedInstance<AppBuilderRootNode>
29+
let sandbox: sinon.SinonSandbox
30+
31+
beforeEach(async () => {
32+
sandbox = sinon.createSandbox()
33+
await fs.delete(path.join(workspaceFolder.uri.fsPath, projectFolder), { recursive: true })
34+
rootNode = sandbox.spy(AppBuilderRootNode.instance)
35+
})
36+
37+
afterEach(async () => {
38+
await fs.delete(path.join(workspaceFolder.uri.fsPath, projectFolder), { recursive: true })
39+
sandbox.restore()
40+
})
41+
42+
it('creates project from Serverless Land integration', async () => {
43+
/**
44+
* Selection:
45+
* - pattern : [Select] 2 apigw-rest-api-lambda-sam
46+
* - runtime : [Select] 3 dotnet
47+
* - iac : [Select] 1 sam
48+
* - location : [Input] From TestFolder.uri
49+
* - name : [Input] "my-project-from-Serverless-Land"
50+
*/
51+
52+
const testWindow = getTestWindow()
53+
const prompterTester = PrompterTester.init({ testWindow })
54+
.handleQuickPick('Select a Pattern for your application', async (quickPick) => {
55+
await quickPick.untilReady()
56+
const options = quickPick.items
57+
Object.entries(parseMetadata.patterns).map(([key, pattern]) => {
58+
options.find((option) => option.label === key && option.detail === pattern.description)
59+
})
60+
quickPick.acceptItem(quickPick.items[1])
61+
})
62+
.handleQuickPick('Select Runtime', async (quickPick) => {
63+
await quickPick.untilReady()
64+
const options = quickPick.items
65+
assert.strictEqual(options[0].label, 'python')
66+
assert.strictEqual(options[1].label, 'javascript')
67+
assert.strictEqual(options[2].label, 'java')
68+
assert.strictEqual(options[3].label, 'dotnet')
69+
quickPick.acceptItem(options[3])
70+
})
71+
.handleQuickPick('Select IaC', async (quickPick) => {
72+
await quickPick.untilReady()
73+
const options = quickPick.items
74+
assert.strictEqual(options[0].label, 'sam')
75+
quickPick.acceptItem(options[0])
76+
})
77+
.handleQuickPick('Select Project Location', async (quickPick) => {
78+
await quickPick.untilReady()
79+
const options = quickPick.items
80+
assert.strictEqual(options[0].label, '$(folder) workspaceFolder')
81+
assert.strictEqual(options[1].label, '$(folder-opened) Select a folder...')
82+
quickPick.acceptItem(options[0])
83+
})
84+
.handleInputBox('Enter Project Name', (inputBox) => {
85+
inputBox.acceptValue('my-project-from-Serverless-Land')
86+
})
87+
.build()
88+
89+
// Validate that the README.md is shown.
90+
testWindow.onDidChangeActiveTextEditor((editors) => {
91+
assert(editors)
92+
const readMe = path.join(workspaceFolder.uri.fsPath, projectFolder, 'README.md')
93+
assert.strictEqual(editors?.document.fileName, readMe)
94+
})
95+
96+
await vscode.commands.executeCommand('aws.toolkit.lambda.createServerlessLandProject')
97+
98+
// projectNodes set from previous step
99+
100+
const projectNode = await rootNode
101+
.getChildren()
102+
.then(
103+
(children) =>
104+
children.find(
105+
(node) =>
106+
node instanceof AppNode && node.label === 'workspaceFolder/my-project-from-Serverless-Land'
107+
) as AppNode | undefined
108+
)
109+
110+
assert.ok(projectNode, 'Expect Serverless Land project node in Application Builder')
111+
112+
// Check App Builder resources
113+
const resourceNodes = await projectNode.getChildren()
114+
assert.strictEqual(resourceNodes.length, 1)
115+
assert.ok(resourceNodes[0] instanceof ResourceNode)
116+
117+
// Validate Lambda resource configuration
118+
const lambdaResource = resourceNodes[0] as ResourceNode
119+
assert.strictEqual(lambdaResource.resource.resource.Type, 'AWS::Serverless::Function')
120+
assert.strictEqual(lambdaResource.resource.resource.Runtime, 'dotnet8')
121+
assert.strictEqual(lambdaResource.resource.resource.Id, 'HelloWorldFunction')
122+
assert.deepStrictEqual(lambdaResource.resource.resource.Events, [
123+
{
124+
Id: 'HelloWorld',
125+
Type: 'Api',
126+
Path: '/hello',
127+
Method: 'get',
128+
},
129+
])
130+
assert.deepStrictEqual(lambdaResource.resource.resource.Environment, {
131+
Variables: {
132+
PARAM1: 'VALUE',
133+
},
134+
})
135+
136+
prompterTester.assertCallAll()
137+
})
138+
})

packages/core/src/testInteg/appBuilder/sidebar/appBuilderNode.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import { detectSamProjects } from '../../../awsService/appBuilder/explorer/detec
1010
import { SamAppLocation } from '../../../awsService/appBuilder/explorer/samProject'
1111
import { AppNode } from '../../../awsService/appBuilder/explorer/nodes/appNode'
1212
import { ResourceNode } from '../../../awsService/appBuilder/explorer/nodes/resourceNode'
13-
import sinon from 'sinon'
13+
import * as sinon from 'sinon'
1414
import { writeSamconfigGlobal, SamConfig } from '../../../shared/sam/config'
1515
import { globals, sleep } from '../../../shared'
1616
import path from 'path'
1717

1818
describe('Application Builder', async () => {
1919
let rootNode: sinon.SinonSpiedInstance<AppBuilderRootNode>
2020
let projects: SamAppLocation[]
21-
let sandbox: sinon.SinonSandbox
2221
let originalWalkThroughState: boolean
2322
let projectNodes: any[]
23+
let sandbox: sinon.SinonSandbox
2424

2525
before(async () => {
2626
sandbox = sinon.createSandbox()
@@ -33,6 +33,7 @@ describe('Application Builder', async () => {
3333
},
3434
])
3535
rootNode = sandbox.spy(AppBuilderRootNode.instance)
36+
3637
projects = await detectSamProjects()
3738

3839
// Set the walkthrough status to true to ensure the root node has a walkthrough node
@@ -41,9 +42,9 @@ describe('Application Builder', async () => {
4142
})
4243

4344
after(async () => {
44-
sandbox.restore()
4545
// Restore original status of walkthroughCompleted status
4646
await globals.globalState.update('aws.toolkit.lambda.walkthroughCompleted', originalWalkThroughState)
47+
sandbox.restore()
4748
})
4849

4950
describe('root node', async () => {

0 commit comments

Comments
 (0)