Skip to content

Commit 3af10b3

Browse files
committed
Clean up on test
Signed-off-by: Tim Bert <5411131+timbms@users.noreply.github.com>
1 parent e50908d commit 3af10b3

File tree

3 files changed

+62
-75
lines changed

3 files changed

+62
-75
lines changed

OpenHABCore/Tests/OpenHABCoreTests/Common.swift

+6-9
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,20 @@ public extension Date {
5454
}
5555

5656
public extension HTTPResponse {
57-
func withEncodedBody(_ encodedBody: String) throws -> (HTTPResponse, HTTPBody) { (self, .init(encodedBody)) }
58-
59-
static var listPetsSuccess: (HTTPResponse, HTTPBody) {
57+
static var listRootSuccess: (HTTPResponse, HTTPBody) {
6058
get throws {
59+
// swiftlint:disable line_length
6160
try Self(status: .ok, headerFields: [.contentType: "application/json"])
6261
.withEncodedBody(
6362
#"""
64-
[
65-
{
66-
"id": 1,
67-
"name": "Fluffz"
68-
}
69-
]
63+
{"version":"8","locale":"en_DE","measurementSystem":"SI","runtimeInfo":{"version":"4.3.2","buildString":"Release Build"},"links":[{"type":"config-descriptions","url":"http://192.168.2.10:8080/rest/config-descriptions"},{"type":"auth","url":"http://192.168.2.10:8080/rest/auth"},{"type":"habpanel","url":"http://192.168.2.10:8080/rest/habpanel"},{"type":"sitemaps","url":"http://192.168.2.10:8080/rest/sitemaps"},{"type":"persistence","url":"http://192.168.2.10:8080/rest/persistence"},{"type":"addons","url":"http://192.168.2.10:8080/rest/addons"},{"type":"things","url":"http://192.168.2.10:8080/rest/things"},{"type":"channel-types","url":"http://192.168.2.10:8080/rest/channel-types"},{"type":"profile-types","url":"http://192.168.2.10:8080/rest/profile-types"},{"type":"module-types","url":"http://192.168.2.10:8080/rest/module-types"},{"type":"links","url":"http://192.168.2.10:8080/rest/links"},{"type":"thing-types","url":"http://192.168.2.10:8080/rest/thing-types"},{"type":"tags","url":"http://192.168.2.10:8080/rest/tags"},{"type":"discovery","url":"http://192.168.2.10:8080/rest/discovery"},{"type":"events","url":"http://192.168.2.10:8080/rest/events"},{"type":"rules","url":"http://192.168.2.10:8080/rest/rules"},{"type":"services","url":"http://192.168.2.10:8080/rest/services"},{"type":"items","url":"http://192.168.2.10:8080/rest/items"},{"type":"actions","url":"http://192.168.2.10:8080/rest/actions"},{"type":"logging","url":"http://192.168.2.10:8080/rest/logging"},{"type":"audio","url":"http://192.168.2.10:8080/rest/audio"},{"type":"voice","url":"http://192.168.2.10:8080/rest/voice"},{"type":"templates","url":"http://192.168.2.10:8080/rest/templates"},{"type":"inbox","url":"http://192.168.2.10:8080/rest/inbox"},{"type":"systeminfo","url":"http://192.168.2.10:8080/rest/systeminfo"},{"type":"ui","url":"http://192.168.2.10:8080/rest/ui"},{"type":"transformations","url":"http://192.168.2.10:8080/rest/transformations"},{"type":"uuid","url":"http://192.168.2.10:8080/rest/uuid"},{"type":"spec","url":"http://192.168.2.10:8080/rest/spec"},{"type":"iconsets","url":"http://192.168.2.10:8080/rest/iconsets"}]}
7064
"""#
7165
)
66+
// swiftlint:enable line_length
7267
}
7368
}
69+
70+
func withEncodedBody(_ encodedBody: String) throws -> (HTTPResponse, HTTPBody) { (self, .init(encodedBody)) }
7471
}
7572

7673
public extension Data {

OpenHABCore/Tests/OpenHABCoreTests/TestClient.swift

-66
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) 2010-2025 Contributors to the openHAB project
2+
//
3+
// See the NOTICE file(s) distributed with this work for additional
4+
// information.
5+
//
6+
// This program and the accompanying materials are made available under the
7+
// terms of the Eclipse Public License 2.0 which is available at
8+
// http://www.eclipse.org/legal/epl-2.0
9+
//
10+
// SPDX-License-Identifier: EPL-2.0
11+
12+
import HTTPTypes
13+
import OpenAPIRuntime
14+
import OpenHABCore
15+
import XCTest
16+
17+
final class TestOpenAPIClient: XCTestCase {
18+
var transport: TestClientTransport!
19+
var client: Client {
20+
get throws {
21+
try .init(
22+
serverURL: URL(validatingOpenAPIServerURL: "/rest"),
23+
configuration: .init(multipartBoundaryGenerator: .constant),
24+
transport: transport
25+
)
26+
}
27+
}
28+
29+
/// Setup method called before the invocation of each test method in the class.
30+
override func setUp() async throws {
31+
try await super.setUp()
32+
continueAfterFailure = false
33+
}
34+
35+
func testgetRoot() async throws {
36+
transport = .init { (request: HTTPRequest, body: HTTPBody?, baseURL: URL, operationID: String) in
37+
XCTAssertEqual(operationID, "getRoot")
38+
XCTAssertEqual(
39+
request.path,
40+
"//"
41+
)
42+
XCTAssertEqual(baseURL.absoluteString, "/rest")
43+
XCTAssertEqual(request.method, .get)
44+
XCTAssertNil(body)
45+
return try HTTPResponse.listRootSuccess
46+
}
47+
let response = try await client.getRoot()
48+
guard case let .ok(value) = response else {
49+
XCTFail("Unexpected response: \(response)")
50+
return
51+
}
52+
switch value.body {
53+
case let .json(rootBean): XCTAssertEqual(rootBean.version, "8")
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)