-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHaystackClientNIOIntegrationTests.swift
More file actions
122 lines (107 loc) · 4.78 KB
/
Copy pathHaystackClientNIOIntegrationTests.swift
File metadata and controls
122 lines (107 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import AsyncHTTPClient
import Foundation
import Haystack
import HaystackClientNIO
import NIO
import Testing
/// To use these tests, run a [Haxall](https://github.com/haxall/haxall) server and set the username and password
/// in the `HAYSTACK_USER` and `HAYSTACK_PASSWORD` environment variables
struct HaystackClientNIOIntegrationTests {
private func withClient(_ block: (Client) async throws -> Void) async throws {
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup))
let client = try Client(
baseUrl: "http://localhost:8080/api/",
username: ProcessInfo.processInfo.environment["HAYSTACK_USER"] ?? "su",
password: ProcessInfo.processInfo.environment["HAYSTACK_PASSWORD"] ?? "su",
httpClient: httpClient
)
try await client.open()
try await block(client)
try await client.close()
try await httpClient.shutdown()
}
@Test func closeAndOpen() async throws {
try await withClient { client in
try print(await client.close())
try print(await client.open())
}
}
@Test func about() async throws {
try await withClient { client in
try print(await client.about().toZinc())
}
}
@Test func defs() async throws {
try await withClient { client in
try print(await client.defs().toZinc())
try print(await client.defs(filter: "lib==^lib:phIoT").toZinc())
try print(await client.defs(limit: Number(1)).toZinc())
try print(await client.defs(filter: "lib==^lib:phIoT", limit: Number(1)).toZinc())
}
}
@Test func libs() async throws {
try await withClient { client in
try print(await client.libs().toZinc())
try print(await client.libs(filter: "lib==^lib:phIoT").toZinc())
try print(await client.libs(limit: Number(1)).toZinc())
try print(await client.libs(filter: "lib==^lib:phIoT", limit: Number(1)).toZinc())
}
}
@Test func ops() async throws {
try await withClient { client in
try print(await client.ops().toZinc())
try print(await client.ops(filter: "lib==^lib:phIoT").toZinc())
try print(await client.ops(limit: Number(1)).toZinc())
try print(await client.ops(filter: "lib==^lib:phIoT", limit: Number(1)).toZinc())
}
}
@Test func filetypes() async throws {
try await withClient { client in
try print(await client.filetypes().toZinc())
try print(await client.filetypes(filter: "lib==^lib:phIoT").toZinc())
try print(await client.filetypes(limit: Number(1)).toZinc())
try print(await client.filetypes(filter: "lib==^lib:phIoT", limit: Number(1)).toZinc())
}
}
@Test func read() async throws {
try await withClient { client in
try print(await client.read(ids: [Ref("28e7fb47-d67ab19a")]).toZinc())
}
}
@Test func readAll() async throws {
try await withClient { client in
try print(await client.read(filter: "site").toZinc())
}
}
@Test func hisRead() async throws {
try await withClient { client in
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .today).toZinc())
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .yesterday).toZinc())
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .date(Date("2022-01-01"))).toZinc())
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .dateRange(from: Date("2022-01-01"), to: Date("2022-02-01"))).toZinc())
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())
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .after(DateTime("2022-01-01T00:00:00Z"))).toZinc())
}
}
@Test func hisWrite() async throws {
try await withClient { client in
try print(await client.hisWrite(
id: Ref("28e7fb7d-e20316e0"),
items: [
HisItem(ts: DateTime("2022-01-01T00:00:00-07:00 Denver"), val: Number(14)),
]
).toZinc())
}
}
@Test func eval() async throws {
try await withClient { client in
try print(await client.eval(expression: "readAll(site)").toZinc())
}
}
@Test func watchUnsub() async throws {
try await withClient { client in
try print(await client.watchUnsubRemove(watchId: "id", ids: [Ref("28e7fb47-d67ab19a")]))
}
}
}