Skip to content

Commit

Permalink
Clean up app initializer infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
rorbech committed Jun 19, 2024
1 parent 97f288c commit f345396
Show file tree
Hide file tree
Showing 34 changed files with 553 additions and 513 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ import io.realm.kotlin.mongodb.sync.SyncConfiguration
import io.realm.kotlin.test.mongodb.common.FLEXIBLE_SYNC_SCHEMA
import io.realm.kotlin.test.mongodb.util.AppAdmin
import io.realm.kotlin.test.mongodb.util.AppAdminImpl
import io.realm.kotlin.test.mongodb.util.AppInitializer
import io.realm.kotlin.test.mongodb.util.AppServicesClient
import io.realm.kotlin.test.mongodb.util.BaasApp
import io.realm.kotlin.test.mongodb.util.Service
import io.realm.kotlin.test.mongodb.util.TestAppInitializer.initializeDefault
import io.realm.kotlin.test.platform.PlatformUtils
import io.realm.kotlin.test.util.TestHelper
import io.realm.kotlin.test.util.use
Expand Down Expand Up @@ -94,27 +92,23 @@ open class TestApp private constructor(
@OptIn(ExperimentalKBsonSerializerApi::class)
constructor(
testId: String?,
appName: String = TEST_APP_PARTITION,
appInitializer: AppInitializer,
dispatcher: CoroutineDispatcher = singleThreadDispatcher("$testId-dispatcher"),
builder: (AppConfiguration.Builder) -> AppConfiguration.Builder = {
it.syncRootDirectory(PlatformUtils.createTempDir("$appName-$testId"))
it.syncRootDirectory(PlatformUtils.createTempDir("${appInitializer.name}-$testId"))
},
debug: Boolean = false,
networkTransport: NetworkTransport? = null,
ejson: EJson = EJson,
initialSetup: suspend AppServicesClient.(app: BaasApp, service: Service) -> Unit = { app: BaasApp, service: Service ->
initializeDefault(app, service)
}
) : this(
dispatcher,
build(
debug = debug,
appName = appName,
appInitializer = appInitializer,
dispatcher = dispatcher,
builder = builder,
networkTransport = networkTransport,
ejson = ejson,
initialSetup = initialSetup
)
)

Expand Down Expand Up @@ -196,20 +190,19 @@ open class TestApp private constructor(
@Suppress("LongParameterList")
fun build(
debug: Boolean,
appName: String,
appInitializer: AppInitializer,
dispatcher: CoroutineDispatcher,
builder: (AppConfiguration.Builder) -> AppConfiguration.Builder,
networkTransport: NetworkTransport?,
ejson: EJson,
initialSetup: suspend AppServicesClient.(app: BaasApp, service: Service) -> Unit
): Pair<App, AppAdmin> {
val appAdmin: AppAdmin = runBlocking(dispatcher) {
AppServicesClient.build(
baseUrl = TEST_SERVER_BASE_URL,
debug = debug,
dispatcher = dispatcher
).run {
val baasApp = getOrCreateApp(appName, initialSetup)
val baasApp = getOrCreateApp(appInitializer)

AppAdminImpl(this, baasApp)
}
Expand Down
Loading

0 comments on commit f345396

Please sign in to comment.