Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "--cwd=/Users/mcrich/Xcode/Assignment-Manager-API"
argument = "--cwd=$(SRCROOT)/Sample Compose Files/Healthchecked Redis"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
Expand Down
12 changes: 12 additions & 0 deletions Sample Compose Files/Healthchecked Redis/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
redis:
restart: always
image: redis:7-alpine
volumes:
- redis-data:/data
healthcheck:
test: "redis-cli ping"
interval: 5s
retries: 20
ports:
- "6379:6379"
18 changes: 18 additions & 0 deletions Sources/Container-Compose/Codable Structs/Healthcheck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,22 @@ public struct Healthcheck: Codable, Hashable {
self.retries = retries
self.timeout = timeout
}

public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

// Handle if `test` is a single string instead of an array
if let test = try? container.decodeIfPresent([String].self, forKey: .test) {
self.test = test
} else if let testString = try? container.decodeIfPresent(String.self, forKey: .test) {
self.test = ["CMD-SHELL", testString]
} else {
self.test = nil
}

self.start_period = try container.decodeIfPresent(String.self, forKey: .start_period)
self.interval = try container.decodeIfPresent(String.self, forKey: .interval)
self.retries = try container.decodeIfPresent(Int.self, forKey: .retries)
self.timeout = try container.decodeIfPresent(String.self, forKey: .timeout)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ struct HealthcheckConfigurationTests {
#expect(healthcheck.test?.first == "CMD")
}

@Test("Parse healthcheck with test command (string)")
func parseHealthcheckWithTestAsSingleString() throws {
let yaml = """
test: "redis-cli ping"
"""

let decoder = YAMLDecoder()
let healthcheck = try decoder.decode(Healthcheck.self, from: yaml)

#expect(healthcheck.test?.count == 2)
#expect(healthcheck.test?.first == "CMD-SHELL")
#expect(healthcheck.test?[1] == "redis-cli ping")
}

@Test("Parse healthcheck with interval")
func parseHealthcheckWithInterval() throws {
let yaml = """
Expand Down