summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPNTests/InMemorySettingsStore.swift
blob: 1f19b6429c2152bbd61cebf0a88990d29a60de7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//
//  InMemorySettingsStore.swift
//  MullvadVPNTests
//
//  Created by Marco Nikic on 2023-10-17.
//  Copyright © 2023 Mullvad VPN AB. All rights reserved.
//

import Foundation
import MullvadSettings

protocol Instantiable {
    init()
}

class InMemorySettingsStore<ThrownError: Error>: SettingsStore where ThrownError: Instantiable {
    private var settings = [SettingsKey: Data]()

    func read(key: SettingsKey) throws -> Data {
        guard settings.keys.contains(key), let value = settings[key] else { throw ThrownError() }
        return value
    }

    func write(_ data: Data, for key: SettingsKey) throws {
        settings[key] = data
    }

    func delete(key: SettingsKey) throws {
        settings.removeValue(forKey: key)
    }
}