@@ -15,12 +15,13 @@ import java.nio.file.Files
15
15
import java.nio.file.Paths
16
16
17
17
18
- internal class SourceFileHasherTest : KoinTest {
18
+ internal class SourceFileHasherTest : KoinTest {
19
19
private val repoAbsolutePath = Paths .get(" " ).toAbsolutePath()
20
20
private val outputBasePath = Files .createTempDirectory(" SourceFileHasherTest" )
21
21
private val fixtureFileTarget = " //cli/src/test/kotlin/com/bazel_diff/hash/fixture:foo.ts"
22
22
private val fixtureFileContent: ByteArray
23
23
private val seed = " seed" .toByteArray()
24
+ private val externalRepoResolver = ExternalRepoResolver (repoAbsolutePath, Paths .get(" bazel" ), outputBasePath)
24
25
25
26
init {
26
27
val path = Paths .get(" cli/src/test/kotlin/com/bazel_diff/hash/fixture/foo.ts" )
@@ -35,7 +36,7 @@ internal class SourceFileHasherTest: KoinTest {
35
36
36
37
@Test
37
38
fun testHashConcreteFile () = runBlocking {
38
- val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, null )
39
+ val hasher = SourceFileHasher (repoAbsolutePath, null , externalRepoResolver )
39
40
val bazelSourceFileTarget = BazelSourceFileTarget (fixtureFileTarget, seed)
40
41
val actual = hasher.digest(bazelSourceFileTarget).toHexString()
41
42
val expected = sha256 {
@@ -48,7 +49,7 @@ internal class SourceFileHasherTest: KoinTest {
48
49
49
50
@Test
50
51
fun testHashConcreteFileInExternalRepo () = runBlocking {
51
- val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, null , setOf (" external_repo" ))
52
+ val hasher = SourceFileHasher (repoAbsolutePath, null , externalRepoResolver , setOf (" external_repo" ))
52
53
val externalRepoFilePath = outputBasePath.resolve(" external/external_repo/path/to/my_file.txt" )
53
54
Files .createDirectories(externalRepoFilePath.parent)
54
55
val externalRepoFileTarget = " @external_repo//path/to:my_file.txt"
@@ -66,7 +67,7 @@ internal class SourceFileHasherTest: KoinTest {
66
67
67
68
@Test
68
69
fun testSoftHashConcreteFile () = runBlocking {
69
- val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, null )
70
+ val hasher = SourceFileHasher (repoAbsolutePath, null , externalRepoResolver )
70
71
val bazelSourceFileTarget = BazelSourceFileTarget (fixtureFileTarget, seed)
71
72
val actual = hasher.softDigest(bazelSourceFileTarget)?.toHexString()
72
73
val expected = sha256 {
@@ -79,7 +80,7 @@ internal class SourceFileHasherTest: KoinTest {
79
80
80
81
@Test
81
82
fun testSoftHashNonExistedFile () = runBlocking {
82
- val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, null )
83
+ val hasher = SourceFileHasher (repoAbsolutePath, null , externalRepoResolver )
83
84
val bazelSourceFileTarget = BazelSourceFileTarget (" //i/do/not/exist" , seed)
84
85
val actual = hasher.softDigest(bazelSourceFileTarget)
85
86
assertThat(actual).isNull()
@@ -88,7 +89,7 @@ internal class SourceFileHasherTest: KoinTest {
88
89
@Test
89
90
fun testSoftHashExternalTarget () = runBlocking {
90
91
val target = " @bazel-diff//some:file"
91
- val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, null )
92
+ val hasher = SourceFileHasher (repoAbsolutePath, null , externalRepoResolver )
92
93
val bazelSourceFileTarget = BazelSourceFileTarget (target, seed)
93
94
val actual = hasher.softDigest(bazelSourceFileTarget)
94
95
assertThat(actual).isNull()
@@ -97,7 +98,7 @@ internal class SourceFileHasherTest: KoinTest {
97
98
@Test
98
99
fun testHashNonExistedFile () = runBlocking {
99
100
val target = " //i/do/not/exist"
100
- val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, null )
101
+ val hasher = SourceFileHasher (repoAbsolutePath, null , externalRepoResolver )
101
102
val bazelSourceFileTarget = BazelSourceFileTarget (target, seed)
102
103
val actual = hasher.digest(bazelSourceFileTarget).toHexString()
103
104
val expected = sha256 {
@@ -110,7 +111,7 @@ internal class SourceFileHasherTest: KoinTest {
110
111
@Test
111
112
fun testHashExternalTarget () = runBlocking {
112
113
val target = " @bazel-diff//some:file"
113
- val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, null )
114
+ val hasher = SourceFileHasher (repoAbsolutePath, null , externalRepoResolver )
114
115
val bazelSourceFileTarget = BazelSourceFileTarget (target, seed)
115
116
val actual = hasher.digest(bazelSourceFileTarget).toHexString()
116
117
val expected = sha256 {}.toHexString()
@@ -120,7 +121,7 @@ internal class SourceFileHasherTest: KoinTest {
120
121
@Test
121
122
fun testHashWithProvidedContentHash () = runBlocking {
122
123
val filenameToContentHash = hashMapOf(" cli/src/test/kotlin/com/bazel_diff/hash/fixture/foo.ts" to " foo-content-hash" )
123
- val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, filenameToContentHash )
124
+ val hasher = SourceFileHasher (repoAbsolutePath, filenameToContentHash, externalRepoResolver )
124
125
val bazelSourceFileTarget = BazelSourceFileTarget (fixtureFileTarget, seed)
125
126
val actual = hasher.digest(bazelSourceFileTarget).toHexString()
126
127
val expected = sha256 {
@@ -134,7 +135,7 @@ internal class SourceFileHasherTest: KoinTest {
134
135
@Test
135
136
fun testHashWithProvidedContentHashButNotInKey () = runBlocking {
136
137
val filenameToContentHash = hashMapOf(" cli/src/test/kotlin/com/bazel_diff/hash/fixture/bar.ts" to " foo-content-hash" )
137
- val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, filenameToContentHash )
138
+ val hasher = SourceFileHasher (repoAbsolutePath, filenameToContentHash, externalRepoResolver )
138
139
val bazelSourceFileTarget = BazelSourceFileTarget (fixtureFileTarget, seed)
139
140
val actual = hasher.digest(bazelSourceFileTarget).toHexString()
140
141
val expected = sha256 {
@@ -149,7 +150,7 @@ internal class SourceFileHasherTest: KoinTest {
149
150
fun testHashWithProvidedContentHashWithLeadingColon () = runBlocking {
150
151
val targetName = " //:cli/src/test/kotlin/com/bazel_diff/hash/fixture/bar.ts"
151
152
val filenameToContentHash = hashMapOf(" cli/src/test/kotlin/com/bazel_diff/hash/fixture/bar.ts" to " foo-content-hash" )
152
- val hasher = SourceFileHasher (repoAbsolutePath, outputBasePath, filenameToContentHash )
153
+ val hasher = SourceFileHasher (repoAbsolutePath, filenameToContentHash, externalRepoResolver )
153
154
val bazelSourceFileTarget = BazelSourceFileTarget (targetName, seed)
154
155
val actual = hasher.digest(bazelSourceFileTarget).toHexString()
155
156
val expected = sha256 {
0 commit comments