File tree Expand file tree Collapse file tree 6 files changed +114
-0
lines changed
androidAndroidTest/kotlin/dev/gitlive/firebase/storage
commonTest/kotlin/dev/gitlive/firebase/storage
iosTest/kotlin/dev/gitlive/firebase/storage
jsTest/kotlin/dev/gitlive/firebase/storage Expand file tree Collapse file tree 6 files changed +114
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+ */
4+
5+ @file:JvmName(" tests" )
6+ package dev.gitlive.firebase.storage
7+
8+ import androidx.test.platform.app.InstrumentationRegistry
9+ import kotlinx.coroutines.CoroutineScope
10+ import kotlinx.coroutines.runBlocking
11+
12+ actual val emulatorHost: String = " 10.0.2.2"
13+
14+ actual val context: Any = InstrumentationRegistry .getInstrumentation().targetContext
15+
16+ actual fun runTest (test : suspend CoroutineScope .() -> Unit ) = runBlocking { test() }
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+ */
4+
5+ package dev.gitlive.firebase.storage
6+
7+ import dev.gitlive.firebase.Firebase
8+ import dev.gitlive.firebase.FirebaseOptions
9+ import dev.gitlive.firebase.apps
10+ import dev.gitlive.firebase.initialize
11+ import kotlinx.coroutines.CoroutineScope
12+ import kotlin.test.BeforeTest
13+
14+ expect val emulatorHost: String
15+ expect val context: Any
16+ expect fun runTest (test : suspend CoroutineScope .() -> Unit )
17+
18+ class FirebaseStorageTest {
19+
20+ @BeforeTest
21+ fun initializeFirebase () {
22+ Firebase
23+ .takeIf { Firebase .apps(context).isEmpty() }
24+ ?.apply {
25+ initialize(
26+ context,
27+ FirebaseOptions (
28+ applicationId = " 1:846484016111:ios:dd1f6688bad7af768c841a" ,
29+ apiKey = " AIzaSyCK87dcMFhzCz_kJVs2cT2AVlqOTLuyWV0" ,
30+ databaseUrl = " https://fir-kotlin-sdk.firebaseio.com" ,
31+ storageBucket = " fir-kotlin-sdk.appspot.com" ,
32+ projectId = " fir-kotlin-sdk" ,
33+ gcmSenderId = " 846484016111"
34+ )
35+ )
36+ Firebase .storage.useEmulator(emulatorHost, 9199 )
37+ }
38+ }
39+
40+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+ */
4+
5+ package dev.gitlive.firebase.storage
6+
7+ import kotlinx.coroutines.CoroutineScope
8+ import kotlinx.coroutines.MainScope
9+ import kotlinx.coroutines.async
10+ import kotlinx.coroutines.runBlocking
11+ import kotlinx.coroutines.yield
12+ import platform.Foundation.NSDate
13+ import platform.Foundation.NSDefaultRunLoopMode
14+ import platform.Foundation.NSRunLoop
15+ import platform.Foundation.create
16+ import platform.Foundation.runMode
17+
18+ actual val emulatorHost: String = " 127.0.0.1"
19+
20+ actual val context: Any = Unit
21+
22+ actual fun runTest (test : suspend CoroutineScope .() -> Unit ) = runBlocking {
23+ val testRun = MainScope ().async { test() }
24+ while (testRun.isActive) {
25+ NSRunLoop .mainRunLoop.runMode(
26+ NSDefaultRunLoopMode ,
27+ beforeDate = NSDate .create(timeInterval = 1.0 , sinceDate = NSDate ())
28+ )
29+ yield ()
30+ }
31+ testRun.await()
32+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+ */
4+
5+ package dev.gitlive.firebase.storage
6+
7+ import kotlinx.coroutines.CoroutineScope
8+
9+ actual val emulatorHost: String = " 127.0.0.1"
10+
11+ actual val context: Any = Unit
12+
13+ actual fun runTest (test : suspend CoroutineScope .() -> Unit ) {
14+ kotlinx.coroutines.test.runTest { test() }
15+ }
Original file line number Diff line number Diff line change 1414 },
1515 "database" : {
1616 "port" : 9000
17+ },
18+ "storage" : {
19+ "port" : 9199
1720 }
1821 }
1922}
Original file line number Diff line number Diff line change 1+ rules_version = '2';
2+ service firebase.storage {
3+ match /b/{bucket}/o {
4+ match /{allPaths=**} {
5+ allow read, write: if true;
6+ }
7+ }
8+ }
You can’t perform that action at this time.
0 commit comments