-
Notifications
You must be signed in to change notification settings - Fork 129
[NFC] Refactor PetstoreConsumerTests to allow multiple versions #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
czechboy0
merged 2 commits into
apple:main
from
czechboy0:hd-refactor-petstore-consumer-tests
Aug 1, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftOpenAPIGenerator open source project | ||
// | ||
// Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
import OpenAPIRuntime | ||
import Foundation | ||
|
||
public enum TestError: Swift.Error, LocalizedError, CustomStringConvertible { | ||
case noHandlerFound(method: HTTPMethod, path: [RouterPathComponent]) | ||
case invalidURLString(String) | ||
case unexpectedValue(Any) | ||
case unexpectedMissingRequestBody | ||
|
||
public var description: String { | ||
switch self { | ||
case .noHandlerFound(let method, let path): | ||
return "No handler found for method \(method.name) and path \(path.stringPath)" | ||
case .invalidURLString(let string): | ||
return "Invalid URL string: \(string)" | ||
case .unexpectedValue(let value): | ||
return "Unexpected value: \(value)" | ||
case .unexpectedMissingRequestBody: | ||
return "Unexpected missing request body" | ||
} | ||
} | ||
|
||
public var errorDescription: String? { | ||
description | ||
} | ||
} | ||
|
||
public extension Date { | ||
static var test: Date { | ||
Date(timeIntervalSince1970: 1_674_036_251) | ||
} | ||
|
||
static var testString: String { | ||
"2023-01-18T10:04:11Z" | ||
} | ||
} | ||
|
||
public extension Array where Element == RouterPathComponent { | ||
var stringPath: String { | ||
map(\.description).joined(separator: "/") | ||
} | ||
} | ||
|
||
public extension Response { | ||
init( | ||
statusCode: Int, | ||
headers: [HeaderField] = [], | ||
encodedBody: String | ||
) { | ||
self.init( | ||
statusCode: statusCode, | ||
headerFields: headers, | ||
body: Data(encodedBody.utf8) | ||
) | ||
} | ||
|
||
static var listPetsSuccess: Self { | ||
.init( | ||
statusCode: 200, | ||
headers: [ | ||
.init(name: "content-type", value: "application/json") | ||
], | ||
encodedBody: #""" | ||
[ | ||
{ | ||
"id": 1, | ||
"name": "Fluffz" | ||
} | ||
] | ||
"""# | ||
) | ||
} | ||
} | ||
|
||
public extension Data { | ||
var pretty: String { | ||
String(decoding: self, as: UTF8.self) | ||
} | ||
|
||
static var abcdString: String { | ||
"abcd" | ||
} | ||
|
||
static var abcd: Data { | ||
Data(abcdString.utf8) | ||
} | ||
|
||
static var efghString: String { | ||
"efgh" | ||
} | ||
|
||
static var quotedEfghString: String { | ||
#""efgh""# | ||
} | ||
|
||
static var efgh: Data { | ||
Data(efghString.utf8) | ||
} | ||
} | ||
|
||
public extension Request { | ||
init( | ||
path: String, | ||
query: String? = nil, | ||
method: HTTPMethod, | ||
headerFields: [HeaderField] = [], | ||
encodedBody: String | ||
) throws { | ||
let body = Data(encodedBody.utf8) | ||
self.init( | ||
path: path, | ||
query: query, | ||
method: method, | ||
headerFields: headerFields, | ||
body: body | ||
) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.