Skip to content

Commit

Permalink
issue #1131 use in-memory Realm for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sosnovsky committed Dec 1, 2021
1 parent 5947f39 commit 050d226
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 2 additions & 3 deletions FlowCrypt/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, AppDelegateGoogleSesssion
var googleAuthSession: OIDExternalUserAgentSession?
let window: UIWindow = UIWindow(frame: UIScreen.main.bounds)

func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let isRunningTests = NSClassFromString("XCTestCase") != nil
if isRunningTests {
func application(_ application: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if application.isRunningTests {
return true
}
GlobalRouter().proceed()
Expand Down
3 changes: 3 additions & 0 deletions FlowCrypt/Extensions/UIApplicationExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ extension UIApplication {
.first(where: \.isKeyWindow)
}

var isRunningTests: Bool {
NSClassFromString("XCTestCase") != nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//

import FlowCryptCommon
import Foundation
import RealmSwift
import UIKit

// swiftlint:disable force_try
protocol EncryptedStorageType: KeyStorageType {
Expand Down Expand Up @@ -82,6 +82,10 @@ final class EncryptedStorage: EncryptedStorageType {
}

private func getConfiguration() throws -> Realm.Configuration {
guard !UIApplication.shared.isRunningTests else {
return Realm.Configuration(inMemoryIdentifier: UUID().uuidString)
}

let path = getDocumentDirectory() + "/" + Constants.encryptedDbFilename
let latestSchemaVersion = currentSchema.version.dbSchemaVersion

Expand Down

0 comments on commit 050d226

Please sign in to comment.