Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4ec6dce

Browse files
add storage emulator, storage rules and test setup
1 parent 5a05210 commit 4ec6dce

File tree

6 files changed

+114
-0
lines changed

6 files changed

+114
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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() }
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

‎test/firebase.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
},
1515
"database": {
1616
"port": 9000
17+
},
18+
"storage": {
19+
"port": 9199
1720
}
1821
}
1922
}

‎test/storage.rules‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /