Skip to content

Commit

Permalink
Refactor remote config code
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarta committed Sep 16, 2024
1 parent 23fa807 commit ad43e4a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ internal class TurboPathConfigurationLoader(val context: Context) : CoroutineSco
loadCachedConfigurationForUrl(url, onCompletion)

launch {
repository.getRemoteConfiguration(url)?.let { remoteConfigJson ->
repository.parseFromJson(remoteConfigJson)?.let { config ->
onCompletion(config)
cacheConfigurationForUrl(url, config)
}
repository.getRemoteConfiguration(url)?.let { config ->
onCompletion(config)
cacheConfigurationForUrl(url, config)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import okhttp3.Request
internal class TurboPathConfigurationRepository {
private val cacheFile = "turbo"

suspend fun getRemoteConfiguration(url: String): String? {
suspend fun getRemoteConfiguration(url: String): TurboPathConfiguration? {
val request = Request.Builder().url(url).build()

return withContext(dispatcherProvider.io) {
issueRequest(request)
issueRequest(request)?.let { parseFromJson(it) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ class TurboPathConfigurationRepositoryTest : BaseRepositoryTest() {

runBlocking {
launch(Dispatchers.Main) {
val json = repository.getRemoteConfiguration(baseUrl())
assertThat(json).isNotNull()

val config = repository.parseFromJson(json!!)
val config = repository.getRemoteConfiguration(baseUrl())
assertThat(config).isNotNull()
assertThat(config?.rules?.size).isEqualTo(2)
}
}
Expand All @@ -50,10 +48,7 @@ class TurboPathConfigurationRepositoryTest : BaseRepositoryTest() {

runBlocking {
launch(Dispatchers.Main) {
val json = repository.getRemoteConfiguration(baseUrl())
assertThat(json).isNotNull()

val config = repository.parseFromJson(json!!)
val config = repository.getRemoteConfiguration(baseUrl())
assertThat(config).isNull()
}
}
Expand Down

0 comments on commit ad43e4a

Please sign in to comment.