Skip to content

Commit ef63664

Browse files
committed
this is so slow
1 parent 198ca8a commit ef63664

File tree

4 files changed

+33
-22
lines changed

4 files changed

+33
-22
lines changed

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ jobs:
378378
run: yarn cli cts generate ${{ matrix.client.language }} --language-version ${{ matrix.client.version }}
379379

380380
- name: Run unit CTS
381-
run: yarn cli cts run ${{ matrix.client.language }} --no-e2e
381+
run: yarn cli cts run ${{ matrix.client.language }} --no-e2e -v
382382

383383
- name: Run e2e CTS
384384
id: cts-e2e

templates/swift/tests/client/tests.mustache

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
{{#testResponse}}
4242
{{#isHelper}}
4343
{{^match.isPrimitive}}
44-
let comparableData = try XCTUnwrap("{{#lambda.escapeQuotes}}{{{match.value}}}{{/lambda.escapeQuotes}}".data(using: .utf8))
45-
try XCTLenientAssertEqual(received: CodableHelper.jsonEncoder.encode(response), expected: comparableData)
44+
try XCTLenientAssertEqual(received: response, expected: "{{#lambda.escapeQuotes}}{{{match.value}}}{{/lambda.escapeQuotes}}")
4645
{{/match.isPrimitive}}
4746
{{#match.isPrimitive}}
4847
{{#match.isNull}}
@@ -54,9 +53,7 @@
5453
{{/match.isPrimitive}}
5554
{{/isHelper}}
5655
{{^isHelper}}
57-
let comparableData = "{{#lambda.escapeQuotes}}{{{match.value}}}{{/lambda.escapeQuotes}}".data(using: .utf8)
58-
let comparableJSON = try XCTUnwrap(comparableData?.jsonString)
59-
XCTAssertEqual(comparableJSON, String(data: try CodableHelper.jsonEncoder.encode(response), encoding: .utf8)!);
56+
XTCJSONEquals(received: response, expected: "{{#lambda.escapeQuotes}}{{{match.value}}}{{/lambda.escapeQuotes}}")
6057
{{/isHelper}}
6158
{{/testResponse}}
6259
{{#shouldScope}}

templates/swift/tests/e2e/e2e.mustache

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,7 @@ final class {{client}}RequestsTestsE2E: XCTestCase {
6363
{{#response}}
6464
let response{{#isGeneric}}: Response<{{#lambda.prefix}}{{{returnType}}}{{/lambda.prefix}}<{{#lambda.prefix}}Hit{{/lambda.prefix}}>>{{/isGeneric}} = {{> tests/method}}
6565
{{#body}}
66-
let responseBody = try XCTUnwrap(response.body)
67-
let responseBodyData = try CodableHelper.jsonEncoder.encode(responseBody)
68-
69-
let expectedBodyData = try XCTUnwrap("{{#lambda.escapeJSON}}{{{body}}}{{/lambda.escapeJSON}}".data(using: .utf8))
70-
71-
XCTLenientAssertEqual(received: responseBodyData, expected: expectedBodyData)
66+
try XCTLenientAssertEqual(received: XCTUnwrap(response.body), expected: "{{#lambda.escapeJSON}}{{{body}}}{{/lambda.escapeJSON}}")
7267
{{/body}}
7368

7469
{{#statusCode}}

tests/output/swift/Tests/Utils/Utils.swift

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,31 @@ struct TestError: Error {
3131
let message: String
3232
}
3333

34-
public func XCTLenientAssertEqual(received: Data, expected: Data) {
34+
public func XTCJSONEquals(received: some Encodable, expected: String) {
35+
let expectedData = expected.data(using: .utf8)!
36+
let receivedJSON = try! JSONEncoder().encode(received)
37+
38+
let dictReceived = try! JSONSerialization.jsonObject(with: receivedJSON) as! NSDictionary
39+
let dictExpected = try! JSONSerialization.jsonObject(with: expectedData) as! NSDictionary
40+
41+
XCTAssertEqual(
42+
dictReceived,
43+
dictExpected,
44+
"""
45+
Received JSON: \(String(data: receivedJSON, encoding: .utf8) ?? "nil")
46+
Expected JSON: \(expected)
47+
"""
48+
)
49+
}
50+
51+
public func XCTLenientAssertEqual(received: some Encodable, expected: String) {
52+
let receivedData = try! JSONEncoder().encode(received)
3553
guard let unionizedObject = try? union(
36-
expected: JSONSerialization.jsonObject(with: expected, options: [.fragmentsAllowed]),
37-
received: JSONSerialization.jsonObject(with: received, options: [.fragmentsAllowed])
54+
expected: JSONSerialization.jsonObject(with: expected.data(using: .utf8)!, options: [.fragmentsAllowed]),
55+
received: JSONSerialization.jsonObject(with: receivedData, options: [.fragmentsAllowed])
3856
) else {
39-
if let receivedString = String(data: received, encoding: .utf8),
40-
let expectedString = String(data: expected, encoding: .utf8) {
41-
XCTAssertEqual(receivedString, expectedString)
57+
if let receivedString = String(data: receivedData, encoding: .utf8) {
58+
XCTAssertEqual(receivedString, expected)
4259
} else {
4360
XCTFail("Unable to unionize received and expected objects")
4461
}
@@ -47,17 +64,19 @@ public func XCTLenientAssertEqual(received: Data, expected: Data) {
4764

4865
guard let unionizedData = try? JSONSerialization.data(withJSONObject: unionizedObject, options: .fragmentsAllowed),
4966
let unionizedJSON = unionizedData.jsonString?.data(using: .utf8),
50-
let expectedJSON = expected.jsonString?.data(using: .utf8),
51-
let unionizedString = String(data: unionizedJSON, encoding: .utf8),
52-
let expectedString = String(data: expectedJSON, encoding: .utf8)
67+
let unionizedString = String(data: unionizedJSON, encoding: .utf8)
5368
else {
5469
XCTFail("Unable to serialize JSON strings")
5570
return
5671
}
5772

5873
XCTAssertEqual(
5974
unionizedString,
60-
expectedString
75+
expected,
76+
"""
77+
Received JSON: \(String(data: receivedData, encoding: .utf8) ?? "nil")
78+
Expected JSON: \(expected)
79+
"""
6180
)
6281
}
6382

0 commit comments

Comments
 (0)