Skip to content

Commit 77fd8c6

Browse files
authored
tests(codecatalyst): assert dev environment vars #3511
1 parent 11affa6 commit 77fd8c6

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

src/testE2E/codecatalyst/client.test.ts

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { captureEventOnce } from '../../test/testUtil'
2929
import { toStream } from '../../shared/utilities/collectionUtils'
3030
import { toCollection } from '../../shared/utilities/asyncCollection'
3131
import { getLogger } from '../../shared/logger'
32+
import { isAwsError } from '../../shared/errors'
3233

3334
let spaceName: CodeCatalystOrg['name']
3435
let projectName: CodeCatalystProject['name']
@@ -238,6 +239,30 @@ describe('Test how this codebase uses the CodeCatalyst API', function () {
238239
assert(lsOutput.split('\n').includes(expectedFile))
239240
})
240241

242+
it('has environment variables that identify the Dev Environment', async function () {
243+
const { SessionProcess, hostname, sshPath } = await prepareDevEnvConnection(client, {
244+
...defaultDevEnv,
245+
})
246+
247+
const output = (
248+
await new SessionProcess(sshPath, [hostname, 'printenv', '|', 'grep', '__DEV_ENVIRONMENT']).run()
249+
).stdout
250+
251+
const parsed: Record<string, string> = {}
252+
for (const line of output.split('\n')) {
253+
const [_, key, value] = line.match(/(.*)=(.*)/) ?? []
254+
if (!key || !value) {
255+
throw new Error(`Failed to parse environment variables from dev env`)
256+
}
257+
258+
parsed[key] = value
259+
}
260+
261+
assert.deepStrictEqual(parsed['__DEV_ENVIRONMENT_ID'], defaultDevEnv.id)
262+
assert.deepStrictEqual(parsed['__DEV_ENVIRONMENT_PROJECT_NAME'], defaultDevEnv.project.name)
263+
assert.deepStrictEqual(parsed['__DEV_ENVIRONMENT_ORGANIZATION_NAME'], defaultDevEnv.org.name)
264+
})
265+
241266
/**
242267
* IMPORTANT: This test takes a while to run. Stopping a Dev Env takes time.
243268
*/
@@ -419,11 +444,22 @@ describe('Test how this codebase uses the CodeCatalyst API', function () {
419444
spaceName: CodeCatalystOrg['name'],
420445
projectName: CodeCatalystProject['name'] = 'aws-vscode-toolkit-integ-test-project'
421446
): Promise<CodeCatalystProject> {
422-
return client.createProject({
423-
spaceName,
424-
displayName: projectName,
425-
description: 'This project is autogenerated by the AWS Toolkit VSCode Integ Test.',
426-
})
447+
try {
448+
return await client.createProject({
449+
spaceName,
450+
displayName: projectName,
451+
description: 'This project is autogenerated by the AWS Toolkit VSCode Integ Test.',
452+
})
453+
} catch (e) {
454+
if (isAwsError(e) && e.code === 'ConflictException') {
455+
return client.getProject({
456+
spaceName,
457+
name: projectName,
458+
})
459+
}
460+
461+
throw e
462+
}
427463
}
428464

429465
/**

0 commit comments

Comments
 (0)