Skip to content

Commit cc46c19

Browse files
feat: Uses swift testing, not XCTest
1 parent 2ffebfc commit cc46c19

29 files changed

+817
-1139
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ import PackageDescription
113113
),
114114
.testTarget(
115115
name: "HaystackServerVaporTests",
116-
dependencies: ["HaystackServerVapor", .product(name: "XCTVapor", package: "vapor")]
116+
dependencies: [
117+
"HaystackServerVapor",
118+
.product(name: "VaporTesting", package: "vapor"),
119+
]
117120
),
118121
]
119122
)
Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,63 @@
1+
import Foundation
12
import Haystack
23
import HaystackClientDarwin
3-
import XCTest
4+
import Testing
45

56
/// To use these tests, run a [Haxall](https://github.com/haxall/haxall) server and set the username and password
67
/// in the `HAYSTACK_USER` and `HAYSTACK_PASSWORD` environment variables
7-
final class HaystackClientDarwinIntegrationTests: XCTestCase {
8+
struct HaystackClientDarwinIntegration {
89
var client: Client = try! Client(
910
baseUrl: "http://localhost:8080/api/",
1011
username: ProcessInfo.processInfo.environment["HAYSTACK_USER"] ?? "su",
1112
password: ProcessInfo.processInfo.environment["HAYSTACK_PASSWORD"] ?? "su"
1213
)
1314

14-
override func setUp() async throws {
15-
try await client.open()
16-
}
17-
18-
override func tearDown() async throws {
19-
try await client.close()
20-
}
21-
22-
func testCloseAndOpen() async throws {
15+
@Test func closeAndOpen() async throws {
2316
try print(await client.close())
2417
try print(await client.open())
2518
}
2619

27-
func testAbout() async throws {
20+
@Test func about() async throws {
2821
try print(await client.about().toZinc())
2922
}
3023

31-
func testDefs() async throws {
24+
@Test func defs() async throws {
3225
try print(await client.defs().toZinc())
3326
try print(await client.defs(filter: "lib==^lib:phIoT").toZinc())
3427
try print(await client.defs(limit: Number(1)).toZinc())
3528
try print(await client.defs(filter: "lib==^lib:phIoT", limit: Number(1)).toZinc())
3629
}
3730

38-
func testLibs() async throws {
31+
@Test func libs() async throws {
3932
try print(await client.libs().toZinc())
4033
try print(await client.libs(filter: "lib==^lib:phIoT").toZinc())
4134
try print(await client.libs(limit: Number(1)).toZinc())
4235
try print(await client.libs(filter: "lib==^lib:phIoT", limit: Number(1)).toZinc())
4336
}
4437

45-
func testOps() async throws {
38+
@Test func ops() async throws {
4639
try print(await client.ops().toZinc())
4740
try print(await client.ops(filter: "lib==^lib:phIoT").toZinc())
4841
try print(await client.ops(limit: Number(1)).toZinc())
4942
try print(await client.ops(filter: "lib==^lib:phIoT", limit: Number(1)).toZinc())
5043
}
5144

52-
func testFiletypes() async throws {
45+
@Test func filetypes() async throws {
5346
try print(await client.filetypes().toZinc())
5447
try print(await client.filetypes(filter: "lib==^lib:phIoT").toZinc())
5548
try print(await client.filetypes(limit: Number(1)).toZinc())
5649
try print(await client.filetypes(filter: "lib==^lib:phIoT", limit: Number(1)).toZinc())
5750
}
5851

59-
func testRead() async throws {
52+
@Test func read() async throws {
6053
try print(await client.read(ids: [Ref("28e7fb47-d67ab19a")]).toZinc())
6154
}
6255

63-
func testReadAll() async throws {
56+
@Test func readAll() async throws {
6457
try print(await client.read(filter: "site").toZinc())
6558
}
6659

67-
func testHisRead() async throws {
60+
@Test func hisRead() async throws {
6861
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .today).toZinc())
6962
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .yesterday).toZinc())
7063
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .date(Date("2022-01-01"))).toZinc())
@@ -73,7 +66,7 @@ final class HaystackClientDarwinIntegrationTests: XCTestCase {
7366
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .after(DateTime("2022-01-01T00:00:00Z"))).toZinc())
7467
}
7568

76-
func testHisWrite() async throws {
69+
@Test func hisWrite() async throws {
7770
try print(await client.hisWrite(
7871
id: Ref("28e7fb7d-e20316e0"),
7972
items: [
@@ -82,11 +75,11 @@ final class HaystackClientDarwinIntegrationTests: XCTestCase {
8275
).toZinc())
8376
}
8477

85-
func testEval() async throws {
78+
@Test func eval() async throws {
8679
try print(await client.eval(expression: "readAll(site)").toZinc())
8780
}
8881

89-
func testWatchUnsub() async throws {
82+
@Test func watchUnsub() async throws {
9083
try print(await client.watchUnsubRemove(watchId: "id", ids: [Ref("28e7fb47-d67ab19a")]))
9184
}
9285
}
Lines changed: 80 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,122 @@
11
import AsyncHTTPClient
2+
import Foundation
23
import Haystack
34
import HaystackClientNIO
45
import NIO
5-
import XCTest
6+
import Testing
67

78
/// To use these tests, run a [Haxall](https://github.com/haxall/haxall) server and set the username and password
89
/// in the `HAYSTACK_USER` and `HAYSTACK_PASSWORD` environment variables
9-
final class HaystackClientNIOIntegrationTests: XCTestCase {
10-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
11-
var httpClient: HTTPClient!
12-
var client: Client!
13-
14-
override func setUp() async throws {
15-
httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup))
16-
client = try Client(
10+
struct HaystackClientNIOIntegrationTests {
11+
private func withClient(_ block: (Client) async throws -> Void) async throws {
12+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
13+
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup))
14+
let client = try Client(
1715
baseUrl: "http://localhost:8080/api/",
1816
username: ProcessInfo.processInfo.environment["HAYSTACK_USER"] ?? "su",
1917
password: ProcessInfo.processInfo.environment["HAYSTACK_PASSWORD"] ?? "su",
2018
httpClient: httpClient
2119
)
2220
try await client.open()
23-
}
2421

25-
override func tearDown() async throws {
22+
try await block(client)
23+
2624
try await client.close()
2725
try await httpClient.shutdown()
2826
}
2927

30-
func testCloseAndOpen() async throws {
31-
try print(await client.close())
32-
try print(await client.open())
28+
@Test func closeAndOpen() async throws {
29+
try await withClient { client in
30+
try print(await client.close())
31+
try print(await client.open())
32+
}
3333
}
3434

35-
func testAbout() async throws {
36-
try print(await client.about().toZinc())
35+
@Test func about() async throws {
36+
try await withClient { client in
37+
try print(await client.about().toZinc())
38+
}
3739
}
3840

39-
func testDefs() async throws {
40-
try print(await client.defs().toZinc())
41-
try print(await client.defs(filter: "lib==^lib:phIoT").toZinc())
42-
try print(await client.defs(limit: Number(1)).toZinc())
43-
try print(await client.defs(filter: "lib==^lib:phIoT", limit: Number(1)).toZinc())
41+
@Test func defs() async throws {
42+
try await withClient { client in
43+
try print(await client.defs().toZinc())
44+
try print(await client.defs(filter: "lib==^lib:phIoT").toZinc())
45+
try print(await client.defs(limit: Number(1)).toZinc())
46+
try print(await client.defs(filter: "lib==^lib:phIoT", limit: Number(1)).toZinc())
47+
}
4448
}
4549

46-
func testLibs() async throws {
47-
try print(await client.libs().toZinc())
48-
try print(await client.libs(filter: "lib==^lib:phIoT").toZinc())
49-
try print(await client.libs(limit: Number(1)).toZinc())
50-
try print(await client.libs(filter: "lib==^lib:phIoT", limit: Number(1)).toZinc())
50+
@Test func libs() async throws {
51+
try await withClient { client in
52+
try print(await client.libs().toZinc())
53+
try print(await client.libs(filter: "lib==^lib:phIoT").toZinc())
54+
try print(await client.libs(limit: Number(1)).toZinc())
55+
try print(await client.libs(filter: "lib==^lib:phIoT", limit: Number(1)).toZinc())
56+
}
5157
}
5258

53-
func testOps() async throws {
54-
try print(await client.ops().toZinc())
55-
try print(await client.ops(filter: "lib==^lib:phIoT").toZinc())
56-
try print(await client.ops(limit: Number(1)).toZinc())
57-
try print(await client.ops(filter: "lib==^lib:phIoT", limit: Number(1)).toZinc())
59+
@Test func ops() async throws {
60+
try await withClient { client in
61+
try print(await client.ops().toZinc())
62+
try print(await client.ops(filter: "lib==^lib:phIoT").toZinc())
63+
try print(await client.ops(limit: Number(1)).toZinc())
64+
try print(await client.ops(filter: "lib==^lib:phIoT", limit: Number(1)).toZinc())
65+
}
5866
}
5967

60-
func testFiletypes() async throws {
61-
try print(await client.filetypes().toZinc())
62-
try print(await client.filetypes(filter: "lib==^lib:phIoT").toZinc())
63-
try print(await client.filetypes(limit: Number(1)).toZinc())
64-
try print(await client.filetypes(filter: "lib==^lib:phIoT", limit: Number(1)).toZinc())
68+
@Test func filetypes() async throws {
69+
try await withClient { client in
70+
try print(await client.filetypes().toZinc())
71+
try print(await client.filetypes(filter: "lib==^lib:phIoT").toZinc())
72+
try print(await client.filetypes(limit: Number(1)).toZinc())
73+
try print(await client.filetypes(filter: "lib==^lib:phIoT", limit: Number(1)).toZinc())
74+
}
6575
}
6676

67-
func testRead() async throws {
68-
try print(await client.read(ids: [Ref("28e7fb47-d67ab19a")]).toZinc())
77+
@Test func read() async throws {
78+
try await withClient { client in
79+
try print(await client.read(ids: [Ref("28e7fb47-d67ab19a")]).toZinc())
80+
}
6981
}
7082

71-
func testReadAll() async throws {
72-
try print(await client.read(filter: "site").toZinc())
83+
@Test func readAll() async throws {
84+
try await withClient { client in
85+
try print(await client.read(filter: "site").toZinc())
86+
}
7387
}
7488

75-
func testHisRead() async throws {
76-
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .today).toZinc())
77-
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .yesterday).toZinc())
78-
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .date(Date("2022-01-01"))).toZinc())
79-
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .dateRange(from: Date("2022-01-01"), to: Date("2022-02-01"))).toZinc())
80-
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .dateTimeRange(from: DateTime("2022-01-01T00:00:00Z"), to: DateTime("2022-02-01T00:00:00Z"))).toZinc())
81-
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .after(DateTime("2022-01-01T00:00:00Z"))).toZinc())
89+
@Test func hisRead() async throws {
90+
try await withClient { client in
91+
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .today).toZinc())
92+
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .yesterday).toZinc())
93+
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .date(Date("2022-01-01"))).toZinc())
94+
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .dateRange(from: Date("2022-01-01"), to: Date("2022-02-01"))).toZinc())
95+
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .dateTimeRange(from: DateTime("2022-01-01T00:00:00Z"), to: DateTime("2022-02-01T00:00:00Z"))).toZinc())
96+
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .after(DateTime("2022-01-01T00:00:00Z"))).toZinc())
97+
}
8298
}
8399

84-
func testHisWrite() async throws {
85-
try print(await client.hisWrite(
86-
id: Ref("28e7fb7d-e20316e0"),
87-
items: [
88-
HisItem(ts: DateTime("2022-01-01T00:00:00-07:00 Denver"), val: Number(14)),
89-
]
90-
).toZinc())
100+
@Test func hisWrite() async throws {
101+
try await withClient { client in
102+
try print(await client.hisWrite(
103+
id: Ref("28e7fb7d-e20316e0"),
104+
items: [
105+
HisItem(ts: DateTime("2022-01-01T00:00:00-07:00 Denver"), val: Number(14)),
106+
]
107+
).toZinc())
108+
}
91109
}
92110

93-
func testEval() async throws {
94-
try print(await client.eval(expression: "readAll(site)").toZinc())
111+
@Test func eval() async throws {
112+
try await withClient { client in
113+
try print(await client.eval(expression: "readAll(site)").toZinc())
114+
}
95115
}
96116

97-
func testWatchUnsub() async throws {
98-
try print(await client.watchUnsubRemove(watchId: "id", ids: [Ref("28e7fb47-d67ab19a")]))
117+
@Test func watchUnsub() async throws {
118+
try await withClient { client in
119+
try print(await client.watchUnsubRemove(watchId: "id", ids: [Ref("28e7fb47-d67ab19a")]))
120+
}
99121
}
100122
}

0 commit comments

Comments
 (0)