Skip to content

Commit

Permalink
tests: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qoomon committed Aug 19, 2024
1 parent fc1d45f commit c61f753
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
build:
runs-on: ubuntu-latest
env:
# MAVEN_OPTS: "-Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn"
MAVEN_OPTS: "-Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn"
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version"
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.0/apache-maven-3.9.0-bin.zip
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.8/apache-maven-3.8.8-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.9.9</version>
<!-- BREAKING CHANGE in https://maven.apache.org/docs/3.9.8/release-notes.html -->
<version>3.9.7</version>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ void noGitVersioning() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.displayStreamBuffers();
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "0.0.0";
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand All @@ -82,12 +83,13 @@ void disableVersioning_cliOption() throws Exception {
writeExtensionConfigFile(projectDir, new Configuration());

// When
Verifier verifier = new Verifier(projectDir.toFile().getAbsolutePath()) {{
addCliOption("-Dversioning.disable");
}};
verifier.executeGoal("verify");
Verifier verifier = getVerifier(projectDir);
verifier.addCliArgument("-Dversioning.disable");
verifier.addCliArguments("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
verifier.verifyTextInLog("skip - versioning is disabled by command option");
String expectedVersion = pomModel.getVersion();
Expand All @@ -109,9 +111,11 @@ void revVersioning_noCommit() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "0000000000000000000000000000000000000000";
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand All @@ -136,9 +140,11 @@ void revVersioning() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = givenCommit.getName();
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand All @@ -163,9 +169,11 @@ void branchVersioning() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "feature-test-gitVersioning";
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand Down Expand Up @@ -193,9 +201,11 @@ void tagVersioning_atBranch() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "v1.0.0-gitVersioning";
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand Down Expand Up @@ -224,9 +234,11 @@ void tagVersioning_detachedHead() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "v1.0.0-gitVersioning";
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand Down Expand Up @@ -255,9 +267,11 @@ void tagVersioning_lightweightTag_atBranch() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "v1.0.0-gitVersioning";
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand Down Expand Up @@ -285,9 +299,11 @@ void tagVersioning_considerTagsOnlyIfHeadIsDetached() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "master-gitVersioning";
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand Down Expand Up @@ -315,9 +331,11 @@ void tagVersioning_environmentVariable() throws Exception {
Verifier verifier = new Verifier(projectDir.toFile().getAbsolutePath()) {{
setEnvironmentVariable("VERSIONING_GIT_BRANCH", "v1.0.0");
}};
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "v1.0.0-gitVersioning";
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand Down Expand Up @@ -380,9 +398,11 @@ void revVersioning_multiModuleProject() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "master-SNAPSHOT";
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand Down Expand Up @@ -439,9 +459,11 @@ void revVersioning_multiModuleProject_ambiguous_artifactId() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "master-SNAPSHOT";
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand Down Expand Up @@ -483,9 +505,11 @@ void branchVersioning_multiModuleProject_noParent() throws Exception {

// When
Verifier verifier = getVerifier(logicProjectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "feature-test-gitVersioning";
verifier.verifyTextInLog("Building " + logicPomModel.getArtifactId() + " " + expectedVersion);
Expand Down Expand Up @@ -539,9 +563,11 @@ void branchVersioning_multiModuleProject_withExternalParent() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "feature-test-gitVersioning";
verifier.verifyTextInLog("Building " + logicPomModel.getArtifactId() + " " + expectedVersion);
Expand Down Expand Up @@ -593,9 +619,11 @@ void branchVersioning_multiModuleProject_withAggregationAndParent() throws Excep

// When
Verifier verifier = getVerifier(logicProjectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "feature-test-gitVersioning";
verifier.verifyTextInLog("Building " + logicPomModel.getArtifactId() + " " + expectedVersion);
Expand Down Expand Up @@ -651,9 +679,11 @@ void dependencyUpdates_multiModuleProject() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "test-gitVersioning";
verifier.verifyTextInLog("Building " + logicPomModel.getArtifactId() + " " + expectedVersion);
Expand Down Expand Up @@ -683,9 +713,11 @@ void branchVersioning_WithBuildTime() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) + "-gitVersioning";
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand All @@ -708,9 +740,11 @@ void apply_emptyRepoGivesExpectedPlusDistanceResult() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "0";
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand All @@ -719,7 +753,7 @@ void apply_emptyRepoGivesExpectedPlusDistanceResult() throws Exception {
assertThat(gitVersionedPomModel.getVersion()).isEqualTo(expectedVersion);
}

}
}

@Test
void apply_singleCommitUntaggedRepoGivesExpectedPlusDistanceResult() throws Exception {
Expand All @@ -735,9 +769,11 @@ void apply_singleCommitUntaggedRepoGivesExpectedPlusDistanceResult() throws Exce

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "1";
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand All @@ -746,7 +782,7 @@ void apply_singleCommitUntaggedRepoGivesExpectedPlusDistanceResult() throws Exce
assertThat(gitVersionedPomModel.getVersion()).isEqualTo(expectedVersion);
}

}
}

@Test
void apply_NoCommitsSinceLastTagGivesExpectedPlusDistanceResult() throws Exception {
Expand All @@ -765,9 +801,11 @@ void apply_NoCommitsSinceLastTagGivesExpectedPlusDistanceResult() throws Excepti

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "677";
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand All @@ -776,7 +814,7 @@ void apply_NoCommitsSinceLastTagGivesExpectedPlusDistanceResult() throws Excepti
assertThat(gitVersionedPomModel.getVersion()).isEqualTo(expectedVersion);
}

}
}

@Test
void apply_TwoCommitsSinceLastTagGivesExpectedPlusDistanceResult() throws Exception {
Expand All @@ -797,9 +835,11 @@ void apply_TwoCommitsSinceLastTagGivesExpectedPlusDistanceResult() throws Except

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "679";
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand All @@ -824,9 +864,11 @@ void apply_DescribeDistanceSnapshotRelease() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
String expectedVersion = "2.0.4";
Model gitVersionedPomModel = readModel(projectDir.resolve(GIT_VERSIONING_POM_NAME).toFile());
assertThat(gitVersionedPomModel.getVersion()).isEqualTo(expectedVersion);
Expand All @@ -852,9 +894,11 @@ void apply_DescribeDistanceSnapshot() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
String expectedVersion = "2.0.4-SNAPSHOT";
Model gitVersionedPomModel = readModel(projectDir.resolve(GIT_VERSIONING_POM_NAME).toFile());
assertThat(gitVersionedPomModel.getVersion()).isEqualTo(expectedVersion);
Expand Down Expand Up @@ -900,9 +944,11 @@ private void apply_TagOnMerged(final boolean firstParent) throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = firstParent ? tagOnMaster : tagOnBranch;
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand All @@ -929,9 +975,11 @@ void apply_UseDescribeTagVersionLabel() throws Exception {

// When
Verifier verifier = getVerifier(projectDir);
verifier.executeGoal("verify");
verifier.addCliArgument("verify");
verifier.execute();

// Then
System.err.println(String.join("\n", verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false)));
verifier.verifyErrorFreeLog();
String expectedVersion = "label";
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
Expand Down

0 comments on commit c61f753

Please sign in to comment.