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 }
|
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 }
|
guard let dictionary = dbReader.get(ip) else { return nil }
|
||||||
return Model.init(dictionary)
|
return Model.init(dictionary)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,11 @@ public class ReaderFactory {
|
||||||
|
|
||||||
public func makeReader<Model>(source: URL, type: DatabaseType) throws -> Reader<Model>? {
|
public func makeReader<Model>(source: URL, type: DatabaseType) throws -> Reader<Model>? {
|
||||||
if !source.isFileURL { return nil }
|
if !source.isFileURL { return nil }
|
||||||
|
let reader = try fileReaderFactory.makeInMemoryReader {
|
||||||
return Reader<Model>(
|
InputStream(url: source) ?? InputStream()
|
||||||
dbReader: 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
2
smart.sh
2
smart.sh
|
@ -1,5 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
/Library/Developer/Toolchains/swift-5.0.3-RELEASE.xctoolchain/usr/bin/swift test \
|
/Library/Developer/Toolchains/swift-5.0.3-RELEASE.xctoolchain/usr/bin/swift test \
|
||||||
--enable-code-coverage \
|
--enable-code-coverage \
|
||||||
--parallel \
|
--parallel \
|
||||||
|
|
Loading…
Reference in New Issue