Skip to content

Commit fc4f284

Browse files
feat: Uses swift testing, not XCTest
1 parent 3657895 commit fc4f284

28 files changed

+806
-1130
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ let package = Package(
7373
name: "HaystackServerTests",
7474
dependencies: [
7575
"HaystackServer",
76-
.product(name: "XCTVapor", package: "vapor", condition: .when(traits: ["ServerVapor"])),
76+
.product(name: "VaporTesting", package: "vapor", condition: .when(traits: ["ServerVapor"])),
7777
]
7878
),
7979
]

Tests/HaystackClientTests/HaystackClientDarwinIntegrationTests.swift

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,64 @@
11
#if ClientDarwin
2+
import Foundation
23
import Haystack
34
import HaystackClient
4-
import XCTest
5+
import Testing
56

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

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

28-
func testAbout() async throws {
21+
@Test func about() async throws {
2922
try print(await client.about().toZinc())
3023
}
3124

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

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

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

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

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

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

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

77-
func testHisWrite() async throws {
70+
@Test func hisWrite() async throws {
7871
try print(await client.hisWrite(
7972
id: Ref("28e7fb7d-e20316e0"),
8073
items: [
@@ -83,11 +76,11 @@ final class HaystackClientDarwinIntegrationTests: XCTestCase {
8376
).toZinc())
8477
}
8578

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

90-
func testWatchUnsub() async throws {
83+
@Test func watchUnsub() async throws {
9184
try print(await client.watchUnsubRemove(watchId: "id", ids: [Ref("28e7fb47-d67ab19a")]))
9285
}
9386
}
Lines changed: 80 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,124 @@
11
#if ClientNIO
22
import AsyncHTTPClient
3+
import Foundation
34
import Haystack
45
import HaystackClient
56
import NIO
6-
import XCTest
7+
import Testing
78

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

26-
override func tearDown() async throws {
23+
try await block(client)
24+
2725
try await client.close()
2826
try await httpClient.shutdown()
2927
}
3028

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

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

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)