System tests ready for execution. Before coverage I'll take another round in the php rat hole to make sure all models are ok.
Signed-off-by: Adam Rocska <adam.rocska@adams.solutions>
This commit is contained in:
parent
d662ad3d22
commit
d646b47877
|
@ -7,7 +7,7 @@ public class Reader<Model> where Model: DictionaryInitialisable {
|
|||
|
||||
init(dbReader: DBReader.Reader) { self.dbReader = dbReader }
|
||||
|
||||
func lookup(_ ip: IpAddress) -> Model? {
|
||||
public func lookup(_ ip: IpAddress) -> Model? {
|
||||
guard let dictionary = dbReader.get(ip) else { return nil }
|
||||
return Model.init(dictionary)
|
||||
}
|
||||
|
|
|
@ -18,12 +18,11 @@ public class ReaderFactory {
|
|||
|
||||
public func makeReader<Model>(source: URL, type: DatabaseType) throws -> Reader<Model>? {
|
||||
if !source.isFileURL { return nil }
|
||||
|
||||
return Reader<Model>(
|
||||
dbReader: try fileReaderFactory.makeInMemoryReader {
|
||||
InputStream(url: source) ?? InputStream()
|
||||
}
|
||||
)
|
||||
let reader = try fileReaderFactory.makeInMemoryReader {
|
||||
InputStream(url: source) ?? InputStream()
|
||||
}
|
||||
precondition(reader.metadata.databaseType.contains(type.rawValue))
|
||||
return Reader<Model>(dbReader: reader)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
import Foundation
|
||||
import XCTest
|
||||
import TestResources
|
||||
import class Api.Reader
|
||||
import struct Api.CountryModel
|
||||
import class Api.ReaderFactory
|
||||
|
||||
class CountryLookupTest: XCTestCase {
|
||||
|
||||
private static var reader: Reader<CountryModel>!
|
||||
private var reader: Reader<CountryModel> { get { return CountryLookupTest.reader } }
|
||||
|
||||
override static func setUp() {
|
||||
super.setUp()
|
||||
let factory = ReaderFactory()
|
||||
guard let url = bundle.url(
|
||||
forResource: "GeoLite2-Country",
|
||||
withExtension: "mmdb",
|
||||
subdirectory: "GeoLite2-Country_20200421"
|
||||
) else {
|
||||
XCTFail("Could not load country database.")
|
||||
return
|
||||
}
|
||||
|
||||
do {
|
||||
try reader = factory.makeReader(source: url, type: .country)
|
||||
} catch {
|
||||
XCTFail("Couldn't initialize reader.")
|
||||
}
|
||||
}
|
||||
|
||||
func testSuccessfulLookup() {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
import Foundation
|
||||
import XCTest
|
||||
import TestResources
|
||||
|
||||
class Wut: XCTestCase {
|
||||
|
||||
func testWut() {
|
||||
print(bundle.path(
|
||||
forResource: "GeoLite2-ASN_20200526/GeoLite2-ASN",
|
||||
ofType: "mmdb"
|
||||
))
|
||||
// print(Bundle.main.bundlePath)
|
||||
// print(Bundle.main.resourcePath)
|
||||
// print(Bundle.main.privateFrameworksPath)
|
||||
// print(Bundle.main.builtInPlugInsPath)
|
||||
// print(Bundle.main.executablePath)
|
||||
// print(Bundle.main.sharedFrameworksPath)
|
||||
// print(Bundle.main.sharedSupportPath)
|
||||
// XCTAssertTrue(false)
|
||||
// let bundle = Bundle(for: Wut.self)
|
||||
// bundle.path(forResource: <#T##String?##Swift.String?#>, ofType: <#T##String?##Swift.String?#>)
|
||||
// print(bundle)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue