-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathBazelModServiceTest.kt
More file actions
72 lines (67 loc) · 1.9 KB
/
BazelModServiceTest.kt
File metadata and controls
72 lines (67 loc) · 1.9 KB
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
package com.bazel_diff.bazel
import assertk.assertThat
import assertk.assertions.isFalse
import com.bazel_diff.SilentLogger
import com.bazel_diff.log.Logger
import java.io.File
import java.nio.file.Paths
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
import org.koin.dsl.module
import org.koin.test.KoinTest
import org.koin.test.get
class BazelModServiceTest : KoinTest {
@get:Rule val temp: TemporaryFolder = TemporaryFolder()
@Test
fun isBzlmodEnabled_returnsFalse_whenWorkspaceHasNoModuleBazel() {
val workspaceDir = temp.newFolder()
startKoin {
modules(
module {
single<Logger> { SilentLogger }
single {
BazelModService(
workingDirectory = workspaceDir.toPath(),
bazelPath = Paths.get("bazel"),
startupOptions = listOf("--enable_bzlmod"),
noBazelrc = true,
)
}
})
}
try {
val service = get<BazelModService>()
assertThat(service.isBzlmodEnabled).isFalse()
} finally {
stopKoin()
}
}
@Test
fun isBzlmodEnabled_returnsConsistentValue_whenWorkspaceHasModuleBazel() {
val workspaceDir = temp.newFolder()
File(workspaceDir, "MODULE.bazel").writeText("module(name = \"test\")\n")
startKoin {
modules(
module {
single<Logger> { SilentLogger }
single {
BazelModService(
workingDirectory = workspaceDir.toPath(),
bazelPath = Paths.get("bazel"),
startupOptions = listOf("--enable_bzlmod"),
noBazelrc = true,
)
}
})
}
try {
val service = get<BazelModService>()
service.isBzlmodEnabled
} finally {
stopKoin()
}
}
}