implement basic fetchers
This commit is contained in:
parent
b8fbed3b15
commit
350f7b0704
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue