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:
Adam Rocska 2020-06-05 16:09:44 +02:00
parent d662ad3d22
commit d646b47877
5 changed files with 44 additions and 32 deletions

View File

@ -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)
} }

View File

@ -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>(
dbReader: try fileReaderFactory.makeInMemoryReader {
InputStream(url: source) ?? InputStream() InputStream(url: source) ?? InputStream()
} }
) precondition(reader.metadata.databaseType.contains(type.rawValue))
return Reader<Model>(dbReader: reader)
} }
} }

View File

@ -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() {
}
}

View File

@ -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)
}
}

View File

@ -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 \