File tree Expand file tree Collapse file tree 2 files changed +44
-5
lines changed
main/kotlin/com/gabrielfeo/gradle/enterprise/api
test/kotlin/com/gabrielfeo/gradle/enterprise/api Expand file tree Collapse file tree 2 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ interface GradleEnterpriseApi {
64
64
65
65
}
66
66
67
- private class RealGradleEnterpriseApi (
67
+ internal class RealGradleEnterpriseApi (
68
68
override val config : Config = Config (),
69
69
) : GradleEnterpriseApi {
70
70
@@ -80,10 +80,10 @@ private class RealGradleEnterpriseApi(
80
80
)
81
81
}
82
82
83
- override val buildsApi: BuildsApi by lazy( retrofit:: create)
84
- override val buildCacheApi: BuildCacheApi by lazy( retrofit:: create)
85
- override val metaApi: MetaApi by lazy( retrofit:: create)
86
- override val testDistributionApi: TestDistributionApi by lazy( retrofit:: create)
83
+ override val buildsApi: BuildsApi by lazy { retrofit. create() }
84
+ override val buildCacheApi: BuildCacheApi by lazy { retrofit. create() }
85
+ override val metaApi: MetaApi by lazy { retrofit. create() }
86
+ override val testDistributionApi: TestDistributionApi by lazy { retrofit. create() }
87
87
88
88
override fun shutdown () {
89
89
okHttpClient.run {
Original file line number Diff line number Diff line change
1
+ package com.gabrielfeo.gradle.enterprise.api
2
+
3
+ import com.gabrielfeo.gradle.enterprise.api.internal.*
4
+ import org.junit.jupiter.api.assertDoesNotThrow
5
+ import org.junit.jupiter.api.assertThrows
6
+ import kotlin.test.Test
7
+ import kotlin.test.assertContains
8
+
9
+ class GradleEnterpriseApiTest {
10
+
11
+ @Test
12
+ fun `Fails eagerly if no API URL` () {
13
+ env = FakeEnv ()
14
+ keychain = FakeKeychain ()
15
+ systemProperties = FakeSystemProperties .linux
16
+ val error = assertThrows<Exception > {
17
+ GradleEnterpriseApi .newInstance(Config ())
18
+ }
19
+ error.assertRootMessageContains(" GRADLE_ENTERPRISE_API_URL" )
20
+ }
21
+
22
+ @Test
23
+ fun `Fails lazily if no API token` () {
24
+ env = FakeEnv (" GRADLE_ENTERPRISE_API_URL" to " example-url" )
25
+ keychain = FakeKeychain ()
26
+ systemProperties = FakeSystemProperties .linux
27
+ val api = assertDoesNotThrow {
28
+ GradleEnterpriseApi .newInstance(Config ())
29
+ }
30
+ val error = assertThrows<Exception > {
31
+ api.buildsApi.toString()
32
+ }
33
+ error.assertRootMessageContains(" GRADLE_ENTERPRISE_API_TOKEN" )
34
+ }
35
+
36
+ private fun Throwable.assertRootMessageContains (text : String ) {
37
+ cause?.assertRootMessageContains(text) ? : assertContains(message.orEmpty(), text)
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments