Skip to content

Commit d709159

Browse files
committed
[SPARK-51870] Support SPARK_GENERATE_GOLDEN_FILES in SQLTests
### What changes were proposed in this pull request? This PR aims to support `SPARK_GENERATE_GOLDEN_FILES` in `SQLTests`. ### Why are the changes needed? To improve `SQLTests`. ### Does this PR introduce _any_ user-facing change? No, this is a test-related improvement. ### How was this patch tested? Pass the CIs and manual review. ``` SPARK_GENERATE_GOLDEN_FILES=1 swift test --filter SQLTests ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes #84 from dongjoon-hyun/SPARK-51870. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 79d8189 commit d709159

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Tests/SparkConnectTests/SQLTests.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import SparkConnect
2626
struct SQLTests {
2727
let fm = FileManager.default
2828
let path = Bundle.module.path(forResource: "queries", ofType: "")!
29-
let encoder = JSONEncoder()
29+
let regenerateGoldenFiles = ProcessInfo.processInfo.environment["SPARK_GENERATE_GOLDEN_FILES"] == "1"
3030

3131
let regexID = /#\d+L?/
3232
let regexPlanId = /plan_id=\d+/
@@ -79,8 +79,13 @@ struct SQLTests {
7979

8080
let sql = try String(contentsOf: URL(fileURLWithPath: "\(path)/\(name)"), encoding: .utf8)
8181
let answer = cleanUp(try await spark.sql(sql).collect().map { $0.toString() }.joined(separator: "\n"))
82-
let expected = cleanUp(try String(contentsOf: URL(fileURLWithPath: "\(path)/\(name).answer"), encoding: .utf8))
83-
#expect(answer == expected.trimmingCharacters(in: .whitespacesAndNewlines))
82+
if (regenerateGoldenFiles) {
83+
let path = "\(FileManager.default.currentDirectoryPath)/Tests/SparkConnectTests/Resources/queries/\(name).answer"
84+
fm.createFile(atPath: path, contents: (answer + "\n").data(using: .utf8)!, attributes: nil)
85+
} else {
86+
let expected = cleanUp(try String(contentsOf: URL(fileURLWithPath: "\(path)/\(name).answer"), encoding: .utf8))
87+
#expect(answer == expected.trimmingCharacters(in: .whitespacesAndNewlines))
88+
}
8489
}
8590
await spark.stop()
8691
}

0 commit comments

Comments
 (0)