Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test app initializer rework #1785

Merged
merged 13 commits into from
Jul 5, 2024
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
* Minimum R8: 8.0.34.

### Internal
- None.
- Reworked test app initializer framework.


## 2.0.1 (YYYY-MM-DD)
## 2.0.1-SNAPSHOT (YYYY-MM-DD)

### Breaking changes
* None.
Expand Down
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 @@ -95,27 +93,23 @@ open class TestApp private constructor(
@OptIn(ExperimentalKBsonSerializerApi::class, ExperimentalCoroutinesApi::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 @@ -198,20 +192,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
Loading