@@ -17,6 +17,7 @@ import java.nio.file.Paths
17
17
18
18
internal class SourceFileHasherTest : KoinTest {
19
19
private val repoAbsolutePath = Paths .get(" " ).toAbsolutePath()
20
+ private val outputBasePath = Files .createTempDirectory(" SourceFileHasherTest" )
20
21
private val fixtureFileTarget = " //cli/src/test/kotlin/com/bazel_diff/hash/fixture:foo.ts"
21
22
private val fixtureFileContent: ByteArray
22
23
private val seed = " seed" .toByteArray()
@@ -34,7 +35,7 @@ internal class SourceFileHasherTest: KoinTest {
34
35
35
36
@Test
36
37
fun testHashConcreteFile () = runBlocking {
37
- val hasher = SourceFileHasher (repoAbsolutePath, null )
38
+ val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, null )
38
39
val bazelSourceFileTarget = BazelSourceFileTarget (fixtureFileTarget, seed)
39
40
val actual = hasher.digest(bazelSourceFileTarget).toHexString()
40
41
val expected = sha256 {
@@ -45,9 +46,27 @@ internal class SourceFileHasherTest: KoinTest {
45
46
assertThat(actual).isEqualTo(expected)
46
47
}
47
48
49
+ @Test
50
+ fun testHashConcreteFileInExternalRepo () = runBlocking {
51
+ val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, null , setOf (" external_repo" ))
52
+ val externalRepoFilePath = outputBasePath.resolve(" external/external_repo/path/to/my_file.txt" )
53
+ Files .createDirectories(externalRepoFilePath.parent)
54
+ val externalRepoFileTarget = " @external_repo//path/to:my_file.txt"
55
+ val externalRepoFileContent = " hello world"
56
+ externalRepoFilePath.toFile().writeText(externalRepoFileContent)
57
+ val bazelSourceFileTarget = BazelSourceFileTarget (externalRepoFileTarget, seed)
58
+ val actual = hasher.digest(bazelSourceFileTarget).toHexString()
59
+ val expected = sha256 {
60
+ safePutBytes(externalRepoFileContent.toByteArray())
61
+ safePutBytes(seed)
62
+ safePutBytes(externalRepoFileTarget.toByteArray())
63
+ }.toHexString()
64
+ assertThat(actual).isEqualTo(expected)
65
+ }
66
+
48
67
@Test
49
68
fun testSoftHashConcreteFile () = runBlocking {
50
- val hasher = SourceFileHasher (repoAbsolutePath, null )
69
+ val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, null )
51
70
val bazelSourceFileTarget = BazelSourceFileTarget (fixtureFileTarget, seed)
52
71
val actual = hasher.softDigest(bazelSourceFileTarget)?.toHexString()
53
72
val expected = sha256 {
@@ -60,7 +79,7 @@ internal class SourceFileHasherTest: KoinTest {
60
79
61
80
@Test
62
81
fun testSoftHashNonExistedFile () = runBlocking {
63
- val hasher = SourceFileHasher (repoAbsolutePath, null )
82
+ val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, null )
64
83
val bazelSourceFileTarget = BazelSourceFileTarget (" //i/do/not/exist" , seed)
65
84
val actual = hasher.softDigest(bazelSourceFileTarget)
66
85
assertThat(actual).isNull()
@@ -69,7 +88,7 @@ internal class SourceFileHasherTest: KoinTest {
69
88
@Test
70
89
fun testSoftHashExternalTarget () = runBlocking {
71
90
val target = " @bazel-diff//some:file"
72
- val hasher = SourceFileHasher (repoAbsolutePath, null )
91
+ val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, null )
73
92
val bazelSourceFileTarget = BazelSourceFileTarget (target, seed)
74
93
val actual = hasher.softDigest(bazelSourceFileTarget)
75
94
assertThat(actual).isNull()
@@ -78,7 +97,7 @@ internal class SourceFileHasherTest: KoinTest {
78
97
@Test
79
98
fun testHashNonExistedFile () = runBlocking {
80
99
val target = " //i/do/not/exist"
81
- val hasher = SourceFileHasher (repoAbsolutePath, null )
100
+ val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, null )
82
101
val bazelSourceFileTarget = BazelSourceFileTarget (target, seed)
83
102
val actual = hasher.digest(bazelSourceFileTarget).toHexString()
84
103
val expected = sha256 {
@@ -91,7 +110,7 @@ internal class SourceFileHasherTest: KoinTest {
91
110
@Test
92
111
fun testHashExternalTarget () = runBlocking {
93
112
val target = " @bazel-diff//some:file"
94
- val hasher = SourceFileHasher (repoAbsolutePath, null )
113
+ val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, null )
95
114
val bazelSourceFileTarget = BazelSourceFileTarget (target, seed)
96
115
val actual = hasher.digest(bazelSourceFileTarget).toHexString()
97
116
val expected = sha256 {}.toHexString()
@@ -101,7 +120,7 @@ internal class SourceFileHasherTest: KoinTest {
101
120
@Test
102
121
fun testHashWithProvidedContentHash () = runBlocking {
103
122
val filenameToContentHash = hashMapOf(" cli/src/test/kotlin/com/bazel_diff/hash/fixture/foo.ts" to " foo-content-hash" )
104
- val hasher = SourceFileHasher (repoAbsolutePath, filenameToContentHash)
123
+ val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, filenameToContentHash)
105
124
val bazelSourceFileTarget = BazelSourceFileTarget (fixtureFileTarget, seed)
106
125
val actual = hasher.digest(bazelSourceFileTarget).toHexString()
107
126
val expected = sha256 {
@@ -115,7 +134,7 @@ internal class SourceFileHasherTest: KoinTest {
115
134
@Test
116
135
fun testHashWithProvidedContentHashButNotInKey () = runBlocking {
117
136
val filenameToContentHash = hashMapOf(" cli/src/test/kotlin/com/bazel_diff/hash/fixture/bar.ts" to " foo-content-hash" )
118
- val hasher = SourceFileHasher (repoAbsolutePath, filenameToContentHash)
137
+ val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, filenameToContentHash)
119
138
val bazelSourceFileTarget = BazelSourceFileTarget (fixtureFileTarget, seed)
120
139
val actual = hasher.digest(bazelSourceFileTarget).toHexString()
121
140
val expected = sha256 {
@@ -130,7 +149,7 @@ internal class SourceFileHasherTest: KoinTest {
130
149
fun testHashWithProvidedContentHashWithLeadingColon () = runBlocking {
131
150
val targetName = " //:cli/src/test/kotlin/com/bazel_diff/hash/fixture/bar.ts"
132
151
val filenameToContentHash = hashMapOf(" cli/src/test/kotlin/com/bazel_diff/hash/fixture/bar.ts" to " foo-content-hash" )
133
- val hasher = SourceFileHasher (repoAbsolutePath, filenameToContentHash)
152
+ val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, filenameToContentHash)
134
153
val bazelSourceFileTarget = BazelSourceFileTarget (targetName, seed)
135
154
val actual = hasher.digest(bazelSourceFileTarget).toHexString()
136
155
val expected = sha256 {
0 commit comments