|
22 | 22 | import java.util.Properties; |
23 | 23 |
|
24 | 24 | import org.gradle.testkit.runner.BuildResult; |
| 25 | +import org.gradle.testkit.runner.InvalidRunnerConfigurationException; |
25 | 26 | import org.gradle.testkit.runner.TaskOutcome; |
| 27 | +import org.gradle.testkit.runner.UnexpectedBuildFailure; |
26 | 28 | import org.junit.jupiter.api.TestTemplate; |
27 | 29 | import org.junit.jupiter.api.extension.ExtendWith; |
28 | 30 |
|
29 | 31 | import org.springframework.boot.gradle.junit.GradleCompatibilityExtension; |
30 | 32 | import org.springframework.boot.gradle.testkit.GradleBuild; |
| 33 | +import org.springframework.boot.loader.tools.FileUtils; |
31 | 34 |
|
32 | 35 | import static org.assertj.core.api.Assertions.assertThat; |
33 | 36 |
|
@@ -92,6 +95,22 @@ public void notUpToDateWhenExecutedTwiceWithFixedTimeAndChangedProjectVersion() |
92 | 95 | assertThat(result.task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); |
93 | 96 | } |
94 | 97 |
|
| 98 | + @TestTemplate |
| 99 | + public void reproducibleOutputWithFixedTime() throws InvalidRunnerConfigurationException, |
| 100 | + UnexpectedBuildFailure, IOException, InterruptedException { |
| 101 | + assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo") |
| 102 | + .getOutcome()).isEqualTo(TaskOutcome.SUCCESS); |
| 103 | + File buildInfoProperties = new File(this.gradleBuild.getProjectDir(), |
| 104 | + "build/build-info.properties"); |
| 105 | + String firstHash = FileUtils.sha1Hash(buildInfoProperties); |
| 106 | + assertThat(buildInfoProperties.delete()).isTrue(); |
| 107 | + Thread.sleep(1500); |
| 108 | + assertThat(this.gradleBuild.build("buildInfo", "-PnullTime") |
| 109 | + .task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); |
| 110 | + String secondHash = FileUtils.sha1Hash(buildInfoProperties); |
| 111 | + assertThat(firstHash).isEqualTo(secondHash); |
| 112 | + } |
| 113 | + |
95 | 114 | private Properties buildInfoProperties() { |
96 | 115 | File file = new File(this.gradleBuild.getProjectDir(), |
97 | 116 | "build/build-info.properties"); |
|
0 commit comments