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 {
6464
6565}
6666
67- private class RealGradleEnterpriseApi (
67+ internal class RealGradleEnterpriseApi (
6868 override val config : Config = Config (),
6969) : GradleEnterpriseApi {
7070
@@ -80,10 +80,10 @@ private class RealGradleEnterpriseApi(
8080 )
8181 }
8282
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() }
8787
8888 override fun shutdown () {
8989 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