|
1 | 1 | package com.bazel_diff.e2e
|
2 | 2 |
|
3 | 3 | import assertk.assertThat
|
4 |
| -import assertk.assertions.contains |
5 | 4 | import assertk.assertions.containsExactlyInAnyOrder
|
6 |
| -import assertk.assertions.containsOnly |
7 | 5 | import assertk.assertions.isEqualTo
|
8 |
| -import com.bazel_diff.Main |
9 | 6 | import com.bazel_diff.cli.BazelDiff
|
10 |
| -import com.bazel_diff.interactor.DeserialiseHashesInteractor |
11 |
| -import com.bazel_diff.testModule |
12 |
| -import com.google.gson.Gson |
13 | 7 | import org.junit.Rule
|
14 | 8 | import org.junit.Test
|
15 | 9 | import org.junit.rules.TemporaryFolder
|
16 |
| -import org.koin.core.context.startKoin |
17 | 10 | import picocli.CommandLine
|
18 | 11 | import java.io.File
|
19 |
| -import java.io.FileInputStream |
20 |
| -import java.io.IOException |
21 |
| -import java.nio.file.Path |
22 | 12 | import java.nio.file.Paths
|
23 |
| -import java.nio.file.StandardCopyOption |
24 | 13 | import java.util.zip.ZipFile
|
25 |
| -import java.util.zip.ZipInputStream |
26 | 14 |
|
27 | 15 |
|
28 | 16 | class E2ETest {
|
@@ -63,6 +51,62 @@ class E2ETest {
|
63 | 51 | assertThat(actual).isEqualTo(expected)
|
64 | 52 | }
|
65 | 53 |
|
| 54 | + @Test |
| 55 | + fun testFineGrainedHashExternalRepo() { |
| 56 | + // The difference between these two snapshot is simply upgrading Guava version. Following |
| 57 | + // is the diff. |
| 58 | + // |
| 59 | + // diff --git a/integration/WORKSPACE b/integration/WORKSPACE |
| 60 | + // index 617a8d6..2cb3c7d 100644 |
| 61 | + // --- a/integration/WORKSPACE |
| 62 | + // +++ b/integration/WORKSPACE |
| 63 | + // @@ -15,7 +15,7 @@ maven_install( |
| 64 | + // name = "bazel_diff_maven", |
| 65 | + // artifacts = [ |
| 66 | + // "junit:junit:4.12", |
| 67 | + // - "com.google.guava:guava:31.0-jre", |
| 68 | + // + "com.google.guava:guava:31.1-jre", |
| 69 | + // ], |
| 70 | + // repositories = [ |
| 71 | + // "http://uk.maven.org/maven2", |
| 72 | + // |
| 73 | + // The project contains a single target that depends on Guava: |
| 74 | + // //src/main/java/com/integration:guava-user |
| 75 | + // |
| 76 | + // So this target, its derived targets, and all other changed external targets should be |
| 77 | + // the only impacted targets. |
| 78 | + val projectA = extractFixtureProject("/fixture/fine-grained-hash-external-repo-test-1.zip") |
| 79 | + val projectB = extractFixtureProject("/fixture/fine-grained-hash-external-repo-test-2.zip") |
| 80 | + |
| 81 | + val workingDirectoryA = projectA |
| 82 | + val workingDirectoryB = projectB |
| 83 | + val bazelPath = "bazel" |
| 84 | + val outputDir = temp.newFolder() |
| 85 | + val from = File(outputDir, "starting_hashes.json") |
| 86 | + val to = File(outputDir, "final_hashes.json") |
| 87 | + val impactedTargetsOutput = File(outputDir, "impacted_targets.txt") |
| 88 | + |
| 89 | + val cli = CommandLine(BazelDiff()) |
| 90 | + //From |
| 91 | + cli.execute( |
| 92 | + "generate-hashes", "-w", workingDirectoryA.absolutePath, "-b", bazelPath, "--fineGrainedHashExternalRepos", "bazel_diff_maven", from.absolutePath |
| 93 | + ) |
| 94 | + //To |
| 95 | + cli.execute( |
| 96 | + "generate-hashes", "-w", workingDirectoryB.absolutePath, "-b", bazelPath, "--fineGrainedHashExternalRepos", "bazel_diff_maven", to.absolutePath |
| 97 | + ) |
| 98 | + //Impacted targets |
| 99 | + cli.execute( |
| 100 | + "get-impacted-targets", "-sh", from.absolutePath, "-fh", to.absolutePath, "-o", impactedTargetsOutput.absolutePath |
| 101 | + ) |
| 102 | + |
| 103 | + val actual: Set<String> = impactedTargetsOutput.readLines().filter { it.isNotBlank() }.toSet() |
| 104 | + val expected: Set<String> = |
| 105 | + javaClass.getResourceAsStream("/fixture/fine-grained-hash-external-repo-test-impacted-targets.txt").use { it.bufferedReader().readLines().filter { it.isNotBlank() }.toSet() } |
| 106 | + |
| 107 | + assertThat(actual).isEqualTo(expected) |
| 108 | + } |
| 109 | + |
66 | 110 | private fun extractFixtureProject(path: String): File {
|
67 | 111 | val testProject = temp.newFolder()
|
68 | 112 | val fixtureCopy = temp.newFile()
|
|
0 commit comments