feat: Adds capturing file client, for tests. Updates bump version tests
This commit is contained in:
@@ -30,9 +30,10 @@ struct CliClientTests {
|
||||
arguments: TestArguments.bumpCases
|
||||
)
|
||||
func bump(type: CliClient.BumpOption, optional: Bool) async throws {
|
||||
let template = optional ? Template.optional("1.0.0") : Template.build("1.0.0")
|
||||
let template = optional ? Template.optional("1.0.0-4-g59bc977") : Template.build("1.0.0")
|
||||
try await run {
|
||||
$0.fileClient.read = { _ in template }
|
||||
$0.fileClient.fileExists = { _ in true }
|
||||
$0.fileClient.read = { @Sendable _ in template }
|
||||
} operation: {
|
||||
let client = CliClient.liveValue
|
||||
let output = try await client.bump(
|
||||
@@ -45,8 +46,17 @@ struct CliClientTests {
|
||||
verbose: true
|
||||
)
|
||||
)
|
||||
|
||||
#expect(output == "/baz/Sources/bar/foo")
|
||||
} assert: { string, _ in
|
||||
let typeString = optional ? "String?" : "String"
|
||||
switch type {
|
||||
case .major:
|
||||
#expect(string.contains("let VERSION: \(typeString) = \"2.0.0\""))
|
||||
case .minor:
|
||||
#expect(string.contains("let VERSION: \(typeString) = \"1.1.0\""))
|
||||
case .patch:
|
||||
#expect(string.contains("let VERSION: \(typeString) = \"1.0.1\""))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,17 +98,31 @@ struct CliClientTests {
|
||||
|
||||
func run(
|
||||
setupDependencies: @escaping (inout DependencyValues) -> Void = { _ in },
|
||||
operation: @Sendable @escaping () async throws -> Void
|
||||
operation: @Sendable @escaping () async throws -> Void,
|
||||
assert: @escaping (String, URL) -> Void = { _, _ in }
|
||||
) async throws {
|
||||
let captured = CapturingWrite()
|
||||
|
||||
try await withDependencies {
|
||||
$0.logger.logLevel = .debug
|
||||
$0.fileClient = .noop
|
||||
$0.fileClient = .capturing(captured)
|
||||
$0.fileClient.fileExists = { _ in false }
|
||||
$0.gitVersionClient = .init { _ in "1.0.0" }
|
||||
$0.gitVersionClient = .init { _, _ in "1.0.0" }
|
||||
setupDependencies(&$0)
|
||||
} operation: {
|
||||
try await operation()
|
||||
}
|
||||
let data = await captured.data
|
||||
let url = await captured.url
|
||||
|
||||
guard let data,
|
||||
let string = String(bytes: data, encoding: .utf8),
|
||||
let url
|
||||
else {
|
||||
throw TestError()
|
||||
}
|
||||
|
||||
assert(string, url)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,3 +133,5 @@ enum TestArguments {
|
||||
$0.append(($1, false))
|
||||
}
|
||||
}
|
||||
|
||||
struct TestError: Error {}
|
||||
|
||||
Reference in New Issue
Block a user