feat: Adds createProject and createJson tests for playbook-client.

This commit is contained in:
2024-12-15 11:59:50 -05:00
parent bc0b740f95
commit 6d0108da0c
5 changed files with 326 additions and 35 deletions

View File

@@ -28,9 +28,16 @@ extension PlaybookClient.RunPlaybook.BuildOptions {
extension PlaybookClient.RunPlaybook.CreateOptions {
func run() async throws {
func run(encoder jsonEncoder: JSONEncoder?) async throws {
try await shared.run { arguments, configuration in
let json = try createJSONData(configuration: configuration)
let jsonData = try createJSONData(
configuration: configuration,
encoder: jsonEncoder
)
guard let json = String(data: jsonData, encoding: .utf8) else {
throw PlaybookClientError.encodingError
}
arguments.append(contentsOf: [
"--tags", "setup-project",
@@ -130,17 +137,20 @@ public extension PlaybookClient.RunPlaybook {
// want the output to be `prettyPrinted` or anything, unless we're running
// tests, so we use a supplied json encoder.
//
extension PlaybookClient.RunPlaybook.CreateOptions {
@_spi(Internal)
public extension PlaybookClient.RunPlaybook.CreateOptions {
func createJSONData(
configuration: Configuration,
encoder: JSONEncoder = .init()
encoder: JSONEncoder?
) throws -> Data {
@Dependency(\.logger) var logger
let templateDir = template.directory ?? configuration.template.directory
let templateRepo = template.url ?? configuration.template.url
let version = template.version ?? configuration.template.version
let encoder = encoder ?? jsonEncoder
let templateDir = template?.directory ?? configuration.template.directory
let templateRepo = template?.url ?? configuration.template.url
let version = template?.version ?? configuration.template.version
logger.debug("""
(\(useLocalTemplateDirectory), \(String(describing: templateDir)), \(String(describing: templateRepo)))
@@ -203,3 +213,9 @@ private struct TemplateRepo: Encodable {
let version: String
}
}
private let jsonEncoder: JSONEncoder = {
let encoder = JSONEncoder()
encoder.outputFormatting = [.withoutEscapingSlashes, .sortedKeys]
return encoder
}()