-
Notifications
You must be signed in to change notification settings - Fork 735
test(lambda): add integration for Serverless Land #6711
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
Merged
nkomonen-amazon
merged 8 commits into
aws:feature/serverlessland
from
vicheey:feature/serverlessland
Mar 5, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7c136ce
test(lambda): add integration for Serverless Land integration
vicheey d7ae430
replace nodefs with fs for parsing file
vicheey 2b08c6d
Merge branch 'aws:feature/serverlessland' into feature/serverlessland
vicheey 290cb50
Apply suggestions from code review
vicheey 18054cc
Update packages/core/src/testInteg/appBuilder/serverlessLand/main.tes…
vicheey 6cfe2c1
fix integration test failure
vicheey 2efef68
prevent integ test transient failure due to spying AppBuilder node
vicheey 92735e3
use sandbox instance instead of sinon
vicheey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
138 changes: 138 additions & 0 deletions
138
packages/core/src/testInteg/appBuilder/serverlessLand/main.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import assert from 'assert' | ||
| import * as vscode from 'vscode' | ||
| import path from 'path' | ||
| import { PrompterTester } from '../../../test/shared/wizards/prompterTester' | ||
| import { describe } from 'mocha' | ||
| import { ProjectMetadata } from '../../../awsService/appBuilder/serverlessLand/metadataManager' | ||
| import fs from '../../../shared/fs/fs' | ||
| import { AppBuilderRootNode } from '../../../awsService/appBuilder/explorer/nodes/rootNode' | ||
| import * as sinon from 'sinon' | ||
| import { AppNode } from '../../../awsService/appBuilder/explorer/nodes/appNode' | ||
| import { ResourceNode } from '../../../awsService/appBuilder/explorer/nodes/resourceNode' | ||
| import { getTestWindow } from '../../../test/shared/vscode/window' | ||
|
|
||
| describe('Serverless Land Integration', async () => { | ||
| const metadataPath = path.resolve( | ||
| __dirname, | ||
| '../../../../../src/awsService/appBuilder/serverlessLand/metadata.json' | ||
| ) | ||
| const metadataContent = await fs.readFileText(metadataPath) | ||
| const parseMetadata = JSON.parse(metadataContent) as ProjectMetadata | ||
| const workspaceFolder = vscode.workspace.workspaceFolders![0] | ||
| const projectFolder = 'my-project-from-Serverless-Land' | ||
| let rootNode: sinon.SinonSpiedInstance<AppBuilderRootNode> | ||
| let sandbox: sinon.SinonSandbox | ||
|
|
||
| beforeEach(async () => { | ||
| sandbox = sinon.createSandbox() | ||
| await fs.delete(path.join(workspaceFolder.uri.fsPath, projectFolder), { recursive: true }) | ||
| rootNode = sandbox.spy(AppBuilderRootNode.instance) | ||
| }) | ||
|
|
||
| afterEach(async () => { | ||
| await fs.delete(path.join(workspaceFolder.uri.fsPath, projectFolder), { recursive: true }) | ||
vicheey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| sandbox.restore() | ||
| }) | ||
|
|
||
| it('creates project from Serverless Land integration', async () => { | ||
| /** | ||
| * Selection: | ||
| * - pattern : [Select] 2 apigw-rest-api-lambda-sam | ||
| * - runtime : [Select] 3 dotnet | ||
| * - iac : [Select] 1 sam | ||
| * - location : [Input] From TestFolder.uri | ||
| * - name : [Input] "my-project-from-Serverless-Land" | ||
| */ | ||
|
|
||
| const testWindow = getTestWindow() | ||
| const prompterTester = PrompterTester.init({ testWindow }) | ||
| .handleQuickPick('Select a Pattern for your application', async (quickPick) => { | ||
| await quickPick.untilReady() | ||
| const options = quickPick.items | ||
| Object.entries(parseMetadata.patterns).map(([key, pattern]) => { | ||
| options.find((option) => option.label === key && option.detail === pattern.description) | ||
| }) | ||
| quickPick.acceptItem(quickPick.items[1]) | ||
| }) | ||
| .handleQuickPick('Select Runtime', async (quickPick) => { | ||
| await quickPick.untilReady() | ||
| const options = quickPick.items | ||
| assert.strictEqual(options[0].label, 'python') | ||
| assert.strictEqual(options[1].label, 'javascript') | ||
| assert.strictEqual(options[2].label, 'java') | ||
| assert.strictEqual(options[3].label, 'dotnet') | ||
| quickPick.acceptItem(options[3]) | ||
| }) | ||
| .handleQuickPick('Select IaC', async (quickPick) => { | ||
| await quickPick.untilReady() | ||
| const options = quickPick.items | ||
| assert.strictEqual(options[0].label, 'sam') | ||
| quickPick.acceptItem(options[0]) | ||
| }) | ||
| .handleQuickPick('Select Project Location', async (quickPick) => { | ||
| await quickPick.untilReady() | ||
| const options = quickPick.items | ||
| assert.strictEqual(options[0].label, '$(folder) workspaceFolder') | ||
| assert.strictEqual(options[1].label, '$(folder-opened) Select a folder...') | ||
| quickPick.acceptItem(options[0]) | ||
| }) | ||
| .handleInputBox('Enter Project Name', (inputBox) => { | ||
| inputBox.acceptValue('my-project-from-Serverless-Land') | ||
| }) | ||
| .build() | ||
|
|
||
| // Validate that the README.md is shown. | ||
| testWindow.onDidChangeActiveTextEditor((editors) => { | ||
| assert(editors) | ||
| const readMe = path.join(workspaceFolder.uri.fsPath, projectFolder, 'README.md') | ||
| assert.strictEqual(editors?.document.fileName, readMe) | ||
| }) | ||
|
|
||
| await vscode.commands.executeCommand('aws.toolkit.lambda.createServerlessLandProject') | ||
|
|
||
| // projectNodes set from previous step | ||
|
|
||
| const projectNode = await rootNode | ||
| .getChildren() | ||
| .then( | ||
| (children) => | ||
| children.find( | ||
| (node) => | ||
| node instanceof AppNode && node.label === 'workspaceFolder/my-project-from-Serverless-Land' | ||
| ) as AppNode | undefined | ||
| ) | ||
|
|
||
| assert.ok(projectNode, 'Expect Serverless Land project node in Application Builder') | ||
|
|
||
| // Check App Builder resources | ||
| const resourceNodes = await projectNode.getChildren() | ||
| assert.strictEqual(resourceNodes.length, 1) | ||
| assert.ok(resourceNodes[0] instanceof ResourceNode) | ||
|
|
||
| // Validate Lambda resource configuration | ||
| const lambdaResource = resourceNodes[0] as ResourceNode | ||
| assert.strictEqual(lambdaResource.resource.resource.Type, 'AWS::Serverless::Function') | ||
| assert.strictEqual(lambdaResource.resource.resource.Runtime, 'dotnet8') | ||
| assert.strictEqual(lambdaResource.resource.resource.Id, 'HelloWorldFunction') | ||
| assert.deepStrictEqual(lambdaResource.resource.resource.Events, [ | ||
| { | ||
| Id: 'HelloWorld', | ||
| Type: 'Api', | ||
| Path: '/hello', | ||
| Method: 'get', | ||
| }, | ||
| ]) | ||
| assert.deepStrictEqual(lambdaResource.resource.resource.Environment, { | ||
| Variables: { | ||
| PARAM1: 'VALUE', | ||
| }, | ||
| }) | ||
|
|
||
| prompterTester.assertCallAll() | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.