Skip to content

Commit 379ba6b

Browse files
committed
add tests
1 parent fe82be7 commit 379ba6b

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

packages/core/src/test/shared/sam/build.test.ts

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
getBuildFlags,
1818
ParamsSource,
1919
runBuild,
20+
SamBuildResult,
2021
} from '../../../shared/sam/build'
2122
import { TreeNode } from '../../../shared/treeview/resourceTreeDataProvider'
2223
import { createWizardTester } from '../wizards/wizardTestUtils'
@@ -32,6 +33,7 @@ import { samconfigCompleteData, validTemplateData } from './samTestUtils'
3233
import { CloudFormationTemplateRegistry } from '../../../shared/fs/templateRegistry'
3334
import { getTestWindow } from '../vscode/window'
3435
import { CancellationError } from '../../../shared/utilities/timeoutUtils'
36+
import { SamAppLocation } from '../../../awsService/appBuilder/explorer/samProject'
3537

3638
describe('SAM BuildWizard', async function () {
3739
const createTester = async (params?: Partial<BuildParams>, arg?: TreeNode | undefined) =>
@@ -388,22 +390,8 @@ describe('SAM runBuild', () => {
388390
verifyCorrectDependencyCall()
389391
})
390392

391-
it('[entry: appbuilder node] with default flags should instantiate correct process in terminal', async () => {
392-
const prompterTester = PrompterTester.init()
393-
.handleQuickPick('Specify parameter source for build', async (quickPick) => {
394-
// Need sometime to wait for the template to search for template file
395-
await quickPick.untilReady()
396-
397-
assert.strictEqual(quickPick.items.length, 2)
398-
const items = quickPick.items
399-
assert.strictEqual(quickPick.items.length, 2)
400-
assert.deepStrictEqual(items[0], { data: ParamsSource.Specify, label: 'Specify build flags' })
401-
assert.deepStrictEqual(items[1].label, 'Use default values')
402-
quickPick.acceptItem(quickPick.items[1])
403-
})
404-
.build()
405-
406-
// Invoke sync command from command palette
393+
it('[entry: appbuilder node] with default flags should instantiate correct process in terminal and show progress notification', async () => {
394+
const prompterTester = getPrompterTester()
407395
const expectedSamAppLocation = {
408396
workspaceFolder: workspaceFolder,
409397
samTemplateUri: templateFile,
@@ -412,6 +400,10 @@ describe('SAM runBuild', () => {
412400

413401
await runBuild(new AppNode(expectedSamAppLocation))
414402

403+
getTestWindow()
404+
.getFirstMessage()
405+
.assertProgress(`Building SAM template at ${expectedSamAppLocation.samTemplateUri.path}`)
406+
415407
assert.deepEqual(mockChildProcessClass.getCall(0).args, [
416408
'sam-cli-path',
417409
[
@@ -437,6 +429,27 @@ describe('SAM runBuild', () => {
437429
prompterTester.assertCallAll()
438430
})
439431

432+
it('[entry: appbuilder node] should throw an error when running two build processes in parallel for the same template', async () => {
433+
const prompterTester = getPrompterTester()
434+
const expectedSamAppLocation = {
435+
workspaceFolder: workspaceFolder,
436+
samTemplateUri: templateFile,
437+
projectRoot: projectRoot,
438+
}
439+
await assert.rejects(
440+
async () => {
441+
await runInParallel(expectedSamAppLocation)
442+
},
443+
(e: any) => {
444+
assert.strictEqual(e instanceof ToolkitError, true)
445+
assert.strictEqual(e.message, 'Template is already being built')
446+
assert.strictEqual(e.code, 'BuildInProgress')
447+
return true
448+
}
449+
)
450+
prompterTester.assertCallAll(undefined, 2)
451+
})
452+
440453
it('[entry: command palette] use samconfig should instantiate correct process in terminal', async () => {
441454
const samconfigFile = vscode.Uri.file(await testFolder.write('samconfig.toml', samconfigCompleteData))
442455

@@ -551,3 +564,23 @@ describe('SAM runBuild', () => {
551564
})
552565
})
553566
})
567+
568+
async function runInParallel(samLocation: SamAppLocation): Promise<[SamBuildResult, SamBuildResult]> {
569+
return Promise.all([runBuild(new AppNode(samLocation)), runBuild(new AppNode(samLocation))])
570+
}
571+
572+
function getPrompterTester() {
573+
return PrompterTester.init()
574+
.handleQuickPick('Specify parameter source for build', async (quickPick) => {
575+
// Need sometime to wait for the template to search for template file
576+
await quickPick.untilReady()
577+
578+
assert.strictEqual(quickPick.items.length, 2)
579+
const items = quickPick.items
580+
assert.strictEqual(quickPick.items.length, 2)
581+
assert.deepStrictEqual(items[0], { data: ParamsSource.Specify, label: 'Specify build flags' })
582+
assert.deepStrictEqual(items[1].label, 'Use default values')
583+
quickPick.acceptItem(quickPick.items[1])
584+
})
585+
.build()
586+
}

packages/core/src/testInteg/sam.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ describe('SAM Integration Tests', async function () {
700700
describe('SAM Build', async function () {
701701
let workspaceFolder: vscode.WorkspaceFolder
702702
// We're testing only one case (python 3.10 (ZIP)) on the integration tests. More niche cases are handled as unit tests.
703-
const scenarioIndex = 2
703+
const scenarioIndex = 3
704704
const scenario = scenarios[scenarioIndex]
705705
let testRoot: string
706706
let sandbox: sinon.SinonSandbox

0 commit comments

Comments
 (0)