Skip to content

Commit

Permalink
Merge pull request #153 from hotwired/fix-configuration-tests
Browse files Browse the repository at this point in the history
Update the path configuration loader coroutine setup so CI can reliably pass
  • Loading branch information
jayohms authored Feb 24, 2021
2 parents bf5227a + b1f2cab commit 9930d03
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package dev.hotwire.turbo.config

import android.content.Context
import dev.hotwire.turbo.util.coroutineScope
import dev.hotwire.turbo.util.toObject
import com.google.gson.reflect.TypeToken
import dev.hotwire.turbo.util.dispatcherProvider
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext

internal class TurboPathConfigurationLoader(val context: Context) {
internal class TurboPathConfigurationLoader(val context: Context) : CoroutineScope {
internal var repository = TurboPathConfigurationRepository()

override val coroutineContext: CoroutineContext
get() = dispatcherProvider.io + Job()

fun load(location: TurboPathConfiguration.Location, onCompletion: (TurboPathConfiguration) -> Unit) {
location.assetFilePath?.let {
loadBundledAssetConfiguration(it, onCompletion)
Expand All @@ -23,7 +29,7 @@ internal class TurboPathConfigurationLoader(val context: Context) {
// Always load the previously cached version first, if available
loadCachedConfigurationForUrl(url, onCompletion)

context.coroutineScope().launch {
launch {
repository.getRemoteConfiguration(url)?.let {
onCompletion(load(it))
cacheConfigurationForUrl(url, load(it))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import dev.hotwire.turbo.config.TurboPathConfiguration.Location
import dev.hotwire.turbo.nav.TurboNavPresentationContext
import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.verify
import dev.hotwire.turbo.BaseRepositoryTest
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
Expand All @@ -15,16 +17,19 @@ import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config

@ExperimentalCoroutinesApi
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [Build.VERSION_CODES.O])
class TurboPathConfigurationTest {
class TurboPathConfigurationTest : BaseRepositoryTest() {
private lateinit var context: Context
private lateinit var pathConfiguration: TurboPathConfiguration
private val mockRepository = mock<TurboPathConfigurationRepository>()
private val url = "https://turbo.hotwire.dev"

@Before
fun setup() {
override fun setup() {
super.setup()

context = ApplicationProvider.getApplicationContext()
pathConfiguration = TurboPathConfiguration(context).apply {
load(Location(assetFilePath = "json/test-configuration.json"))
Expand Down

0 comments on commit 9930d03

Please sign in to comment.