implement basic fetchers

This commit is contained in:
Alexandr Goncharov 2020-06-10 03:16:15 +03:00
parent b8fbed3b15
commit 350f7b0704
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,19 @@
import Foundation
/// Namespace for the predefined fetchers
enum Fetcher { }
extension Fetcher {
static let direct: (Data) -> CommonConfigurationProvider.Fetcher = { data in
return { data }
}
static let file: (String) -> CommonConfigurationProvider.Fetcher = { configName in
return {
let url = URL(fileURLWithPath: configName, isDirectory: false)
print(url)
return try Data(contentsOf: url)
}
}
}

View File

@ -0,0 +1,14 @@
import XCTest
@testable import Conf
final class FileFetcherTests: XCTestCase {
func testSuccess() throws {
let load = Fetcher.file("Tests/Resources/valid.env")
_ = try load()
}
func testError() throws {
let load = Fetcher.file("file that not exist")
XCTAssertThrowsError(try load())
}
}