Skip to content

Commit df7a433

Browse files
committed
Add regression test for example config file
Adds a test that decodes the real `config/machines.example.json` from the repo to catch schema regressions. Also verifies that unknown fields like `_comment` are safely ignored by the custom `init(from:)` decoder.
1 parent 9f29a9a commit df7a433

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎mac-app/Tests/CloudMachineAppTests/MachinesConfigTests.swift‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,28 @@ final class MachinesConfigTests: XCTestCase {
128128
remoteRootFolder: "CloudMachine", machines: [])
129129
XCTAssertNil(config.limitGB(forMachineKey: "nieznana-maszyna"))
130130
}
131+
132+
// MARK: - config/machines.example.json
133+
134+
/// Dekoduje PRAWDZIWY plik z repo (nie fixture w tescie) - regresja tutaj
135+
/// oznaczaloby, ze wlasny przykladowy config projektu przestal sie parsowac
136+
/// (np. po zmianie schematu bez zaktualizowania pliku). Sprawdza tez, ze
137+
/// dodatkowe, nierozpoznane pole `_comment` jest bezpiecznie ignorowane
138+
/// przez niestandardowy `init(from:)`.
139+
func testDecode_realExampleConfigFileParsesCorrectly() throws {
140+
let exampleConfigPath = URL(fileURLWithPath: #filePath)
141+
.deletingLastPathComponent() // CloudMachineAppTests
142+
.deletingLastPathComponent() // Tests
143+
.deletingLastPathComponent() // mac-app
144+
.deletingLastPathComponent() // CloudMachine (repo root)
145+
.appendingPathComponent("config/machines.example.json")
146+
147+
let data = try Data(contentsOf: exampleConfigPath)
148+
let config = try JSONDecoder().decode(MachinesConfig.self, from: data)
149+
150+
XCTAssertEqual(config.remoteName, "gdrive-cloudmachine")
151+
XCTAssertEqual(config.remoteRootFolder, "CloudMachine")
152+
XCTAssertEqual(config.machines.count, 2)
153+
XCTAssertEqual(config.machines.map(\.key).sorted(), ["imac-domowy", "macbook-pro-marcin"])
154+
}
131155
}

0 commit comments

Comments
 (0)