Skip to content

Commit c0d444b

Browse files
authored
Remove hard-coded version in migration-tool-tests test script (#5366)
1 parent 68334e8 commit c0d444b

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

test/migration-tool-tests/src/test/resources/after/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<dependency>
2929
<groupId>software.amazon.awssdk</groupId>
3030
<artifactId>bom</artifactId>
31-
<version>2.26.16-SNAPSHOT</version>
31+
<version>V2_VERSION</version>
3232
<type>pom</type>
3333
<scope>import</scope>
3434
</dependency>
@@ -40,22 +40,22 @@
4040
<dependency>
4141
<groupId>software.amazon.awssdk</groupId>
4242
<artifactId>sqs</artifactId>
43-
<version>2.26.16-SNAPSHOT</version>
43+
<version>V2_VERSION</version>
4444
</dependency>
4545
<dependency>
4646
<groupId>software.amazon.awssdk</groupId>
4747
<artifactId>apache-client</artifactId>
48-
<version>2.26.16-SNAPSHOT</version>
48+
<version>V2_VERSION</version>
4949
</dependency>
5050
<dependency>
5151
<groupId>software.amazon.awssdk</groupId>
5252
<artifactId>netty-nio-client</artifactId>
53-
<version>2.26.16-SNAPSHOT</version>
53+
<version>V2_VERSION</version>
5454
</dependency>
5555
<dependency>
5656
<groupId>software.amazon.awssdk</groupId>
5757
<artifactId>s3</artifactId>
58-
<version>2.26.16-SNAPSHOT</version>
58+
<version>V2_VERSION</version>
5959
</dependency>
6060
</dependencies>
6161
</project>

test/migration-tool-tests/src/test/resources/run-test

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,40 @@ import os
77
import shutil, errno
88
import argparse
99
import sys
10+
from pathlib import Path
1011

1112
RESOURCE_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "resources")
1213
BEFORE_DIR = os.path.join(RESOURCE_DIR, "before")
1314
AFTER_DIR = os.path.join(RESOURCE_DIR, "after")
1415
TARGET_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(os.path.join(__file__, "../../")))), "target/generated-test-sources/project")
16+
TARGET_AFTER_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(os.path.join(__file__, "../../")))), "target/generated-test-sources/after")
17+
AFTER_POM = os.path.join(TARGET_AFTER_DIR, "pom.xml")
18+
1519
def main():
1620
parser = argparse.ArgumentParser()
1721
parser.add_argument('-v', '--version', dest='version',
1822
default='')
1923
args = parser.parse_args()
2024
run_test(args.version.strip())
2125

26+
# It copies "src/test/resources/before" and "src/test/resources/after" directory to "target/generated-test-sources/project"
27+
# and "target/generated-test-sources/after" respectively and then execute rewrite command in "target/generated-test-sources/project".
28+
# It verifies the correctness of the transformation by comparing the directory to "target/generated-test-sources/after" and ensuring it compiles.
2229
def run_test(version):
2330
if os.path.exists(TARGET_DIR) and os.path.isdir(TARGET_DIR):
2431
shutil.rmtree(TARGET_DIR)
2532
copy_directory(BEFORE_DIR, TARGET_DIR)
33+
copy_directory(AFTER_DIR, TARGET_AFTER_DIR)
2634

2735
subprocess.run(["mvn", "org.openrewrite.maven:rewrite-maven-plugin:5.21.0:run",
2836
"-Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:migration-tool:"+ version,
2937
"-Drewrite.activeRecipes=software.amazon.awssdk.UpgradeJavaSdk2"], cwd=TARGET_DIR, check=True)
3038
shutil.rmtree(os.path.join(TARGET_DIR, "target"))
31-
comparison = filecmp.dircmp(TARGET_DIR, AFTER_DIR)
32-
is_same = compare_directory(filecmp.dircmp(TARGET_DIR, AFTER_DIR))
39+
40+
pom_file = Path(AFTER_POM)
41+
pom_file.write_text(pom_file.read_text().replace('V2_VERSION', version))
42+
43+
is_same = compare_directory(filecmp.dircmp(TARGET_DIR, TARGET_AFTER_DIR))
3344
if not is_same:
3445
raise Exception("The transformed directory('target/generated-test-sources/project') does not match with the expected one('src/test/resources/after')")
3546
result = subprocess.run(["mvn", "package"], cwd=TARGET_DIR, capture_output=True, check=True)

0 commit comments

Comments
 (0)