-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related to #73. The DefaultInstance would be initialized with the default Config eagerly when building a new instance with configuration via code. If there were no URL environment variable set, the DefaultInstance init would throw due to a missing URL in its config. Fix by ensuring that the default Config is initialized lazily.
- Loading branch information
1 parent
9e064e4
commit 891e755
Showing
10 changed files
with
77 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 19 additions & 2 deletions
21
...otlin/com/gabrielfeo/gradle/enterprise/api/internal/GradleEnterpriseApiIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,33 @@ | ||
package com.gabrielfeo.gradle.enterprise.api.internal | ||
|
||
import com.gabrielfeo.gradle.enterprise.api.Config | ||
import com.gabrielfeo.gradle.enterprise.api.GradleEnterpriseApi | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.Test | ||
import org.junit.jupiter.api.assertDoesNotThrow | ||
import kotlin.test.assertEquals | ||
import kotlin.test.Test | ||
|
||
class GradleEnterpriseApiIntegrationTest { | ||
|
||
@Test | ||
fun canFetchBuilds() = runTest { | ||
fun canFetchBuildsWithDefaultInstance() = runTest { | ||
env = RealEnv | ||
keychain = RealKeychain(RealSystemProperties) | ||
val builds = GradleEnterpriseApi.buildsApi.getBuilds(since = 0, maxBuilds = 1) | ||
assertEquals(1, builds.size) | ||
GradleEnterpriseApi.shutdown() | ||
} | ||
|
||
@Test | ||
fun canBuildNewInstanceWithPureCodeConfiguration() = runTest { | ||
env = FakeEnv() | ||
keychain = FakeKeychain() | ||
assertDoesNotThrow { | ||
val config = Config( | ||
apiUrl = "https://google.com/api/", | ||
apiToken = { "" }, | ||
) | ||
GradleEnterpriseApi.newInstance(config) | ||
} | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...ationTest/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/KeychainIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
library/src/test/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/FakeEnv.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,2 @@ | ||
package com.gabrielfeo.gradle.enterprise.api.internal | ||
|
||
class FakeEnv( | ||
vararg vars: Pair<String, String?>, | ||
) : Env { | ||
|
||
private val vars = vars.toMap(HashMap()) | ||
|
||
override fun get(name: String) = vars[name] | ||
|
||
operator fun set(name: String, value: String?) = vars.put(name, value) | ||
operator fun contains(name: String) = name in vars | ||
} |
10 changes: 0 additions & 10 deletions
10
library/src/test/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/FakeKeychain.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,2 @@ | ||
package com.gabrielfeo.gradle.enterprise.api.internal | ||
|
||
internal class FakeKeychain( | ||
vararg entries: Pair<String, String>, | ||
) : Keychain { | ||
|
||
private val entries = entries.toMap() | ||
|
||
override fun get(entry: String) = | ||
entries[entry]?.let { KeychainResult.Success(it) } | ||
?: KeychainResult.Error("entry $entry not mocked") | ||
} |
16 changes: 0 additions & 16 deletions
16
...ary/src/test/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/FakeSystemProperties.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,2 @@ | ||
package com.gabrielfeo.gradle.enterprise.api.internal | ||
|
||
class FakeSystemProperties( | ||
vararg vars: Pair<String, String?>, | ||
) : SystemProperties { | ||
|
||
companion object { | ||
val macOs = FakeSystemProperties("os.name" to "Mac OS X") | ||
val linux = FakeSystemProperties("os.name" to "Linux") | ||
} | ||
|
||
private val vars = vars.toMap(HashMap()) | ||
|
||
override fun get(name: String) = vars[name] | ||
|
||
operator fun set(name: String, value: String?) = vars.put(name, value) | ||
operator fun contains(name: String) = name in vars | ||
} |
13 changes: 13 additions & 0 deletions
13
library/src/testFixtures/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/FakeEnv.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.gabrielfeo.gradle.enterprise.api.internal | ||
|
||
class FakeEnv( | ||
vararg vars: Pair<String, String?>, | ||
) : Env { | ||
|
||
private val vars = vars.toMap(HashMap()) | ||
|
||
override fun get(name: String) = vars[name] | ||
|
||
operator fun set(name: String, value: String?) = vars.put(name, value) | ||
operator fun contains(name: String) = name in vars | ||
} |
12 changes: 12 additions & 0 deletions
12
...ary/src/testFixtures/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/FakeKeychain.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.gabrielfeo.gradle.enterprise.api.internal | ||
|
||
internal class FakeKeychain( | ||
vararg entries: Pair<String, String>, | ||
) : Keychain { | ||
|
||
private val entries = entries.toMap() | ||
|
||
override fun get(entry: String) = | ||
entries[entry]?.let { KeychainResult.Success(it) } | ||
?: KeychainResult.Error("entry $entry not mocked") | ||
} |
18 changes: 18 additions & 0 deletions
18
...testFixtures/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/FakeSystemProperties.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.gabrielfeo.gradle.enterprise.api.internal | ||
|
||
class FakeSystemProperties( | ||
vararg vars: Pair<String, String?>, | ||
) : SystemProperties { | ||
|
||
companion object { | ||
val macOs = FakeSystemProperties("os.name" to "Mac OS X") | ||
val linux = FakeSystemProperties("os.name" to "Linux") | ||
} | ||
|
||
private val vars = vars.toMap(HashMap()) | ||
|
||
override fun get(name: String) = vars[name] | ||
|
||
operator fun set(name: String, value: String?) = vars.put(name, value) | ||
operator fun contains(name: String) = name in vars | ||
} |