diff --git a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip01Core/hints/HintIndexerTest.kt b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip01Core/hints/HintIndexerTest.kt index d6c0fd534..4c4293e51 100644 --- a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip01Core/hints/HintIndexerTest.kt +++ b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip01Core/hints/HintIndexerTest.kt @@ -56,18 +56,20 @@ class HintIndexerTest { ) } - val relays = - TestResourceLoader() - .loadString("relayDB.txt") - .split('\n') - .mapNotNull { - val relay = RelayUrlNormalizer.normalizeOrNull(it) - if (relay == null || relay.isLocalHost()) { - null - } else { - relay + val relays by + lazy { + TestResourceLoader() + .loadString("relayDB.txt") + .split('\n') + .mapNotNull { + val relay = RelayUrlNormalizer.normalizeOrNull(it) + if (relay == null || relay.isLocalHost()) { + null + } else { + relay + } } - } + } val indexer by lazy { val result = HintIndexer() diff --git a/quartz/src/iosTest/kotlin/com/vitorpamplona/quartz/TestResourceLoader.kt b/quartz/src/iosTest/kotlin/com/vitorpamplona/quartz/TestResourceLoader.kt index 01c653066..493c189e2 100644 --- a/quartz/src/iosTest/kotlin/com/vitorpamplona/quartz/TestResourceLoader.kt +++ b/quartz/src/iosTest/kotlin/com/vitorpamplona/quartz/TestResourceLoader.kt @@ -32,11 +32,22 @@ import platform.darwin.NSObjectMeta actual class TestResourceLoader { @OptIn(ExperimentalForeignApi::class, BetaInteropApi::class) actual fun loadString(file: String): String { - val bundle = NSBundle.Companion.bundleForClass(BundleMarker) + // Split the filename and extension (e.g., "data.json" -> "data", "json") + val basename = file.substringBeforeLast(".") + val extension = file.substringAfterLast(".", "") + + // Locate the file in the main application bundle val path = - bundle.pathForResource(file, ofType = null) + NSBundle.mainBundle.pathForResource(basename, ofType = extension) ?: throw IllegalArgumentException("Resource not found: $file") - return NSString.Companion.stringWithContentsOfFile(path, encoding = NSUTF8StringEncoding, error = null)!! + + // Read the file content as a UTF-8 string + return NSString + .stringWithContentsOfFile( + path = path, + encoding = NSUTF8StringEncoding, + error = null, + ).toString() } private class BundleMarker : NSObject() {