-
Notifications
You must be signed in to change notification settings - Fork 47
/
BazelReleaseTest.kt
79 lines (64 loc) · 2.07 KB
/
BazelReleaseTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package org.jetbrains.bsp.bazel.bazelrunner
import com.google.common.base.Charsets
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
import java.nio.file.Path
import kotlin.io.path.createDirectories
import kotlin.io.path.createTempDirectory
import kotlin.io.path.writeText
class BazelReleaseTest {
@Test
fun `should handle old bazel`() {
// given & when
val release = BazelRelease.fromReleaseString("release 4.0.0")
// then
release?.major shouldBe 4
release?.isRelativeWorkspacePath("//abc") shouldBe true
}
@Test
fun `should handle new bazel`() {
// given & when
val release = BazelRelease.fromReleaseString("release 6.0.0")
// then
release?.major shouldBe 6
release?.isRelativeWorkspacePath("@//abc") shouldBe true
release?.isRelativeWorkspacePath("@@//abc") shouldBe true
}
@Test
fun `should handle new bazel unofficial`() {
// given & when
val release = BazelRelease.fromReleaseString("release 6.0.0-pre20230102")
// then
release?.major shouldBe 6
}
@Test
fun `should handle new bazel multi-digit version`() {
// given & when
val release = BazelRelease.fromReleaseString("release 16.0.0")
// then
release?.major shouldBe 16
}
@Test
fun `should fall back to last supported version in case of error`() {
// given & when
val release = BazelRelease.fromReleaseString("debug test").orLatestSupported()
// then
release.major shouldBe 6
}
@Test
fun `should correctly parse bazelversion`() {
// given & when
val path = copyBazelVersionToTmp()
val release = BazelRelease.fromBazelVersionFile(path.parent)
// then
release?.major shouldBe 6
}
private fun copyBazelVersionToTmp() : Path {
val inputStream = BazelReleaseTest::class.java.getResourceAsStream("/.bazelversion")
val content = inputStream?.bufferedReader(Charsets.UTF_8)?.readText()
val tempDir = createTempDirectory("workspace").createDirectories()
val tempFile = tempDir.resolve(".bazelversion")
content?.let { tempFile.writeText(it) }
return tempFile
}
}