Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ import PackageDescription
),
.testTarget(
name: "HaystackServerVaporTests",
dependencies: ["HaystackServerVapor", .product(name: "XCTVapor", package: "vapor")]
dependencies: [
"HaystackServerVapor",
.product(name: "VaporTesting", package: "vapor"),
]
),
]
)
Expand Down Expand Up @@ -204,7 +207,10 @@ import PackageDescription
),
.testTarget(
name: "HaystackServerVaporTests",
dependencies: ["HaystackServerVapor", .product(name: "XCTVapor", package: "vapor")]
dependencies: [
"HaystackServerVapor",
.product(name: "VaporTesting", package: "vapor"),
]
),
]
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,70 +1,63 @@
import Foundation
import Haystack
import HaystackClientDarwin
import XCTest
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
final class HaystackClientDarwinIntegrationTests: XCTestCase {
struct HaystackClientDarwinIntegration {
var client: Client = try! Client(
baseUrl: "http://localhost:8080/api/",
username: ProcessInfo.processInfo.environment["HAYSTACK_USER"] ?? "su",
password: ProcessInfo.processInfo.environment["HAYSTACK_PASSWORD"] ?? "su"
)

override func setUp() async throws {
try await client.open()
}

override func tearDown() async throws {
try await client.close()
}

func testCloseAndOpen() async throws {
@Test func closeAndOpen() async throws {
try print(await client.close())
try print(await client.open())
}

func testAbout() async throws {
@Test func about() async throws {
try print(await client.about().toZinc())
}

func testDefs() async throws {
@Test func defs() async throws {
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())
}

func testLibs() async throws {
@Test func libs() async throws {
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())
}

func testOps() async throws {
@Test func ops() async throws {
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())
}

func testFiletypes() async throws {
@Test func filetypes() async throws {
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())
}

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

func testReadAll() async throws {
@Test func readAll() async throws {
try print(await client.read(filter: "site").toZinc())
}

func testHisRead() async throws {
@Test func hisRead() async throws {
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())
Expand All @@ -73,7 +66,7 @@ final class HaystackClientDarwinIntegrationTests: XCTestCase {
try print(await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .after(DateTime("2022-01-01T00:00:00Z"))).toZinc())
}

func testHisWrite() async throws {
@Test func hisWrite() async throws {
try print(await client.hisWrite(
id: Ref("28e7fb7d-e20316e0"),
items: [
Expand All @@ -82,11 +75,11 @@ final class HaystackClientDarwinIntegrationTests: XCTestCase {
).toZinc())
}

func testEval() async throws {
@Test func eval() async throws {
try print(await client.eval(expression: "readAll(site)").toZinc())
}

func testWatchUnsub() async throws {
@Test func watchUnsub() async throws {
try print(await client.watchUnsubRemove(watchId: "id", ids: [Ref("28e7fb47-d67ab19a")]))
}
}
Original file line number Diff line number Diff line change
@@ -1,100 +1,122 @@
import AsyncHTTPClient
import Foundation
import Haystack
import HaystackClientNIO
import NIO
import XCTest
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
final class HaystackClientNIOIntegrationTests: XCTestCase {
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
var httpClient: HTTPClient!
var client: Client!

override func setUp() async throws {
httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup))
client = try Client(
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()
}

override func tearDown() async throws {
try await block(client)

try await client.close()
try await httpClient.shutdown()
}

func testCloseAndOpen() async throws {
try print(await client.close())
try print(await client.open())
@Test func closeAndOpen() async throws {
try await withClient { client in
try print(await client.close())
try print(await client.open())
}
}

func testAbout() async throws {
try print(await client.about().toZinc())
@Test func about() async throws {
try await withClient { client in
try print(await client.about().toZinc())
}
}

func testDefs() async throws {
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 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())
}
}

func testLibs() async throws {
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 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())
}
}

func testOps() async throws {
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 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())
}
}

func testFiletypes() async throws {
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 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())
}
}

func testRead() async throws {
try print(await client.read(ids: [Ref("28e7fb47-d67ab19a")]).toZinc())
@Test func read() async throws {
try await withClient { client in
try print(await client.read(ids: [Ref("28e7fb47-d67ab19a")]).toZinc())
}
}

func testReadAll() async throws {
try print(await client.read(filter: "site").toZinc())
@Test func readAll() async throws {
try await withClient { client in
try print(await client.read(filter: "site").toZinc())
}
}

func testHisRead() async throws {
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 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())
}
}

func testHisWrite() async throws {
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 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())
}
}

func testEval() async throws {
try print(await client.eval(expression: "readAll(site)").toZinc())
@Test func eval() async throws {
try await withClient { client in
try print(await client.eval(expression: "readAll(site)").toZinc())
}
}

func testWatchUnsub() async throws {
try print(await client.watchUnsubRemove(watchId: "id", ids: [Ref("28e7fb47-d67ab19a")]))
@Test func watchUnsub() async throws {
try await withClient { client in
try print(await client.watchUnsubRemove(watchId: "id", ids: [Ref("28e7fb47-d67ab19a")]))
}
}
}
Loading
Loading