-
Notifications
You must be signed in to change notification settings - Fork 647
test(amazonq): add more tests for /transform #6183
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
Merged
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5c1d84d
tests(amazonq): improve test coverage
d7fd12a
add E2E test
e3c044c
update comment
ec64432
add UI test
ff72ea1
add all files needed for UI test
599e8c1
fix lint errors
24093c1
add more UI tests
8c47d58
small rename of test
d21a334
nit: variable rename
2b3fe64
put E2E tests together
2b51d02
fix import
85bdfef
remove duplicate notification
1d1fa50
make tests pass
e451f5b
add debug logs temporarily
533d55f
add more log statements
5dbbf63
skip test since we get throttled
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
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
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
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
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
86 changes: 86 additions & 0 deletions
86
packages/core/src/testE2E/amazonQTransform/transformByQ.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,86 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import * as path from 'path' | ||
import { setValidConnection } from '../util/connection' | ||
import assert from 'assert' | ||
import { JDKVersion, TransformationType, transformByQState } from '../../codewhisperer' | ||
import { | ||
processLanguageUpgradeTransformFormInput, | ||
setMaven, | ||
startTransformByQ, | ||
} from '../../codewhisperer/commands/startTransformByQ' | ||
import { fs } from '../../shared' | ||
import { TestFolder } from '../../test/testUtil' | ||
|
||
describe('transformByQ', async function () { | ||
let tempDir = '' | ||
let tempFileName = '' | ||
let tempFilePath = '' | ||
let validConnection: boolean | ||
|
||
const javaFileContents = `public class MyApp { | ||
public static void main(String[] args) { | ||
Integer temp = new Integer("1234"); | ||
} | ||
}` | ||
|
||
const pomXmlContents = `<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.example</groupId> | ||
<artifactId>basic-java-app</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project>` | ||
|
||
before(async function () { | ||
validConnection = await setValidConnection() | ||
if (!validConnection) { | ||
this.skip() | ||
} | ||
tempDir = path.join((await TestFolder.create()).path, 'qct-java-upgrade-test') | ||
tempFileName = 'MyApp.java' | ||
tempFilePath = path.join(tempDir, tempFileName) | ||
await fs.writeFile(tempFilePath, javaFileContents) | ||
tempFileName = 'pom.xml' | ||
tempFilePath = path.join(tempDir, tempFileName) | ||
await fs.writeFile(tempFilePath, pomXmlContents) | ||
}) | ||
|
||
// TODO: this test 1) is skipped in GitHub CI due to no valid connection (see line 60 above) and | ||
// 2) even locally, fails due to the max test duration being set to 30s (this test takes ~5m) | ||
// Once both of the above are resolved, this test will pass | ||
// You can manually override the 30s limit (in setupUtil.ts) to confirm that the test passes locally | ||
it('WHEN transforming a Java 8 project E2E THEN job is successful', async function () { | ||
transformByQState.setTransformationType(TransformationType.LANGUAGE_UPGRADE) | ||
await setMaven() | ||
await processLanguageUpgradeTransformFormInput(tempDir, JDKVersion.JDK8, JDKVersion.JDK17) | ||
await startTransformByQ() | ||
assert.strictEqual(transformByQState.getPolledJobStatus(), 'COMPLETED') | ||
}) | ||
}) |
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 |
---|---|---|
|
@@ -10,11 +10,10 @@ import * as codeWhisperer from '../../codewhisperer/client/codewhisperer' | |
import assert from 'assert' | ||
import { getSha256, uploadArtifactToS3, zipCode } from '../../codewhisperer/service/transformByQ/transformApiHandler' | ||
import request from '../../shared/request' | ||
import AdmZip from 'adm-zip' | ||
import { setValidConnection } from '../util/connection' | ||
import { transformByQState, ZipManifest } from '../../codewhisperer/models/model' | ||
import globals from '../../shared/extensionGlobals' | ||
import { fs } from '../../shared' | ||
import { setValidConnection } from '../../testE2E/util/connection' | ||
|
||
describe('transformByQ', async function () { | ||
let tempDir = '' | ||
|
@@ -35,10 +34,6 @@ describe('transformByQ', async function () { | |
await fs.writeFile(tempFilePath, 'sample content for the test file') | ||
transformByQState.setProjectPath(tempDir) | ||
const zipCodeResult = await zipCode({ | ||
dependenciesFolder: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not used for these tests |
||
path: tempFilePath, | ||
name: tempFileName, | ||
}, | ||
projectPath: tempDir, | ||
zipManifest: new ZipManifest(), | ||
}) | ||
|
@@ -87,7 +82,7 @@ describe('transformByQ', async function () { | |
) | ||
}) | ||
|
||
it('WHEN createUploadUrl THEN URL uses HTTPS and sets 60 second expiration', async function () { | ||
it('WHEN createUploadUrl THEN URL uses HTTPS and sets 30 minute expiration', async function () { | ||
const buffer = Buffer.from(await fs.readFileBytes(zippedCodePath)) | ||
const sha256 = getSha256(buffer) | ||
const response = await codeWhisperer.codeWhispererClient.createUploadUrl({ | ||
|
@@ -96,17 +91,8 @@ describe('transformByQ', async function () { | |
uploadIntent: CodeWhispererConstants.uploadIntent, | ||
}) | ||
const uploadUrl = response.uploadUrl | ||
const usesHttpsAndExpiresAfter60Seconds = uploadUrl.includes('https') && uploadUrl.includes('X-Amz-Expires=60') | ||
const usesHttpsAndExpiresAfter60Seconds = | ||
uploadUrl.includes('https') && uploadUrl.includes('X-Amz-Expires=1800') | ||
assert.strictEqual(usesHttpsAndExpiresAfter60Seconds, true) | ||
}) | ||
|
||
it('WHEN zipCode THEN ZIP contains all expected files and no unexpected files', async function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this test to the file above with the other |
||
const zipFiles = new AdmZip(zippedCodePath).getEntries() | ||
const zipFileNames: string[] = [] | ||
zipFiles.forEach((file) => { | ||
zipFileNames.push(file.name) | ||
}) | ||
assert.strictEqual(zipFileNames.length, 2) // expecting only a dummy txt file and a manifest.json | ||
assert.strictEqual(zipFileNames.includes(tempFileName) && zipFileNames.includes('manifest.json'), true) | ||
}) | ||
}) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This above function was previously in
transformApiHandler.ts
, just moving it here so it's in a shared utils file