Skip to content

Commit ea24a6c

Browse files
committed
test(swift-testing): migrate ConfigTests to Swift Testing (phase 3)\n\n- Replace XCTest with Swift Testing\n- Use local ELG/threadpool with safe shutdown via defer\n- No production code changes
1 parent 8ec9705 commit ea24a6c

File tree

1 file changed

+33
-37
lines changed

1 file changed

+33
-37
lines changed
Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,42 @@
1-
2-
import XCTest
1+
import Testing
32
import Casbin
43
import NIO
54

6-
final class ConfigTests: XCTestCase {
7-
var elg = MultiThreadedEventLoopGroup(numberOfThreads: 1)
8-
var pool = NIOThreadPool(numberOfThreads: 1)
9-
deinit {
10-
do {
11-
try pool.syncShutdownGracefully()
12-
try elg.syncShutdownGracefully()
13-
} catch {
14-
}
15-
}
16-
5+
@Suite("Config parsing")
6+
struct ConfigTests {
7+
@Test("load from file and get/set")
178
func testGet() throws {
189
let filePath = #file.components(separatedBy: "ConfigTests.swift")[0] + "examples/testini.ini"
10+
let pool = NIOThreadPool(numberOfThreads: 1)
1911
pool.start()
12+
defer { try? pool.syncShutdownGracefully() }
13+
let elg = MultiThreadedEventLoopGroup(numberOfThreads: 1)
14+
defer { try? elg.syncShutdownGracefully() }
2015
let fileIo = NonBlockingFileIO(threadPool: pool)
21-
var config = try Config.from(file: filePath, fileIo: fileIo, on: elg.next())
22-
.wait()
2316

24-
XCTAssertEqual(true, config.getBool(key: "debug"))
25-
XCTAssertEqual(64, config.getInt(key: "math::math.i64"))
26-
XCTAssertEqual(64.1, config.getFloat(key: "math::math.f64"))
27-
XCTAssertEqual("10.0.0.1", config.get(key: "mysql::mysql.master.host"))
17+
var config = try Config.from(file: filePath, fileIo: fileIo, on: elg.next()).wait()
18+
19+
#expect(config.getBool(key: "debug") == true)
20+
#expect(config.getInt(key: "math::math.i64") == 64)
21+
#expect(config.getFloat(key: "math::math.f64") == 64.1)
22+
#expect(config.get(key: "mysql::mysql.master.host") == "10.0.0.1")
23+
2824
config.set(key: "other::key1", value: "new test key")
29-
XCTAssertEqual("new test key", config.get(key: "other::key1"))
25+
#expect(config.get(key: "other::key1") == "new test key")
3026
config.set(key: "other::key1", value: "test key")
31-
XCTAssertEqual("test key", config.get(key: "other::key1"))
32-
XCTAssertEqual("r.sub==p.sub&&r.obj==p.obj", config.get(key: "multi1::name"))
33-
XCTAssertEqual("r.sub==p.sub&&r.obj==p.obj", config.get(key: "multi2::name"))
34-
XCTAssertEqual("r.sub==p.sub&&r.obj==p.obj", config.get(key: "multi3::name"))
35-
XCTAssertEqual("", config.get(key: "multi4::name"))
36-
XCTAssertEqual("r.sub==p.sub&&r.obj==p.obj", config.get(key: "multi5::name"))
37-
try pool.syncShutdownGracefully()
38-
try elg.syncShutdownGracefully()
27+
#expect(config.get(key: "other::key1") == "test key")
28+
29+
#expect(config.get(key: "multi1::name") == "r.sub==p.sub&&r.obj==p.obj")
30+
#expect(config.get(key: "multi2::name") == "r.sub==p.sub&&r.obj==p.obj")
31+
#expect(config.get(key: "multi3::name") == "r.sub==p.sub&&r.obj==p.obj")
32+
#expect(config.get(key: "multi4::name") == "")
33+
#expect(config.get(key: "multi5::name") == "r.sub==p.sub&&r.obj==p.obj")
3934
}
4035

36+
@Test("load from text and get/set")
4137
func testFromText() throws {
38+
let elg = MultiThreadedEventLoopGroup(numberOfThreads: 1)
39+
defer { try? elg.syncShutdownGracefully() }
4240
let text = #"""
4341
# test config
4442
debug = true
@@ -63,16 +61,14 @@ final class ConfigTests: XCTestCase {
6361
"""#
6462

6563
var config = try Config.from(text: text, on: elg.next()).wait()
66-
XCTAssertEqual(true, config.getBool(key: "debug"))
67-
XCTAssertEqual(64, config.getInt(key: "math::math.i64"))
68-
XCTAssertEqual(64.1, config.getFloat(key: "math::math.f64"))
69-
XCTAssertEqual("10.0.0.1", config.get(key: "mysql::mysql.master.host"))
64+
#expect(config.getBool(key: "debug") == true)
65+
#expect(config.getInt(key: "math::math.i64") == 64)
66+
#expect(config.getFloat(key: "math::math.f64") == 64.1)
67+
#expect(config.get(key: "mysql::mysql.master.host") == "10.0.0.1")
68+
7069
config.set(key: "other::key1", value: "new test key")
71-
XCTAssertEqual("new test key", config.get(key: "other::key1"))
70+
#expect(config.get(key: "other::key1") == "new test key")
7271
config.set(key: "other::key1", value: "test key")
73-
XCTAssertEqual("test key", config.get(key: "other::key1"))
74-
75-
try pool.syncShutdownGracefully()
76-
try elg.syncShutdownGracefully()
72+
#expect(config.get(key: "other::key1") == "test key")
7773
}
7874
}

0 commit comments

Comments
 (0)