Skip to content

Commit beabe17

Browse files
test: add mapping tests for dns_search and build target and fix implementation
1 parent 108e758 commit beabe17

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

Sources/Container-Compose/Commands/ComposeUp.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,12 @@ extension ComposeUp {
640640
runArgs.append(runtime)
641641
}
642642

643+
// Map dns search if present
644+
if let dnsSearch = service.dns_search {
645+
runArgs.append("--dns-search")
646+
runArgs.append(dnsSearch)
647+
}
648+
643649
// Map init flag if present (support both explicit Bool and optional presence)
644650
// Note: Specifying init_image also implies --init
645651
if service.`init` == true || service.init_image != nil {

Tests/Container-Compose-StaticTests/BuildConfigurationTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ struct BuildConfigurationTests {
6565
#expect(build.args?["NODE_VERSION"] == "18")
6666
#expect(build.args?["ENV"] == "production")
6767
}
68+
69+
@Test("Parse build with target stage")
70+
func parseBuildWithTarget() throws {
71+
let yaml = """
72+
context: .
73+
target: builder
74+
"""
75+
76+
let decoder = YAMLDecoder()
77+
let build = try decoder.decode(Build.self, from: yaml)
78+
79+
#expect(build.context == ".")
80+
#expect(build.target == "builder")
81+
}
6882

6983

7084
@Test("Service with build configuration")

Tests/Container-Compose-StaticTests/ComposeUpMappingTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,20 @@ final class ComposeUpMappingTests: XCTestCase {
120120

121121
XCTAssertTrue(entryIdx < imageIdx, "Expected --entrypoint to appear before image, but args: \(args)")
122122
}
123+
124+
func testDNSSearchMapping() throws {
125+
let yaml = """
126+
services:
127+
app:
128+
image: busybox:latest
129+
dns_search: "my-namespace.local"
130+
"""
131+
let dockerCompose = try YAMLDecoder().decode(DockerCompose.self, from: yaml)
132+
guard let service = dockerCompose.services["app"] ?? nil else { return XCTFail("Service 'app' missing") }
133+
134+
let args = try ComposeUp.makeRunArgs(service: service, serviceName: "app", image: nil, dockerCompose: dockerCompose, projectName: "proj", detach: false, cwd: "/tmp", environmentVariables: [:])
135+
136+
XCTAssertTrue(args.contains("--dns-search"), "Expected --dns-search flag present in args: \(args)")
137+
XCTAssertTrue(args.contains("my-namespace.local"), "Expected dns search value present in args: \(args)")
138+
}
123139
}

0 commit comments

Comments
 (0)