Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions api/src/test/java/org/apache/iceberg/TestIcebergBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
package org.apache.iceberg;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Locale;
import java.util.regex.Pattern;
import org.junit.jupiter.api.Test;
Expand All @@ -37,6 +41,34 @@ public void testFullVersion() {
+ ")");
}

@Test
public void testVersionNotUnspecified() {
assertThat(IcebergBuild.version()).isNotEqualTo("unspecified");
}

@Test
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajantha-bhat Added this test, all good?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

public void testVersionMatchesSystemProperty() {
assumeThat(System.getProperty("project.version")).isNotNull();
assertThat(IcebergBuild.version())
.isEqualTo(System.getProperty("project.version"))
.as("IcebergBuild.version() should match system property project.version");
}

/**
* This test is for Source Releases. When we have a source release we use a version.txt file in
* the parent directory of this module to actually set the "version" which should be included in
* the gradle build properties used by IcebergBuild.
*/
@Test
public void testVersionMatchesFile() throws IOException {
Path versionPath = Paths.get("../version.txt").toAbsolutePath();
assumeThat(java.nio.file.Files.exists(versionPath)).isTrue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

If we set the project.version in the system property for tests in build.gradle

test {
    systemProperty "project.version", project.version
}

we can always check

assertThat(IcebergBuild.version())
        .isEqualTo(System.getProperty("project.version"))

This way we don't need two testcase and also it won't be a conditional test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good suggestion, but I really want to test that file. I'm trying to test against the thing we know must be correct. We basically directly pipe this value into version.txt in our source-release script. If we somehow bungle gradle in the future and that value doesn't match the text file for whatever reason I'd like to know. I can add this test as well as an assert though

String versionText = java.nio.file.Files.readString(versionPath).trim();
assertThat(IcebergBuild.version())
.isEqualTo(versionText)
.as("IcebergBuild.version() should match version file");
}

@Test
public void testVersion() {
assertThat(IcebergBuild.version()).as("Should not use unknown version").isNotEqualTo("unknown");
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ gitProperties {
failOnNoGitDirectory = true
keys = ['git.branch', 'git.build.version', 'git.closest.tag.name','git.commit.id.abbrev', 'git.commit.id',
'git.commit.message.short', 'git.commit.time', 'git.tags']
version = projectVersion
}
generateGitProperties.outputs.upToDateWhen { false }

Expand Down Expand Up @@ -233,6 +234,8 @@ subprojects {
events "failed"
exceptionFormat "full"
}

systemProperty 'project.version', project.version
}

plugins.withType(ScalaPlugin.class) {
Expand Down