Skip to content

Commit

Permalink
[WIP] Update to pass conformance tests RC3
Browse files Browse the repository at this point in the history
  • Loading branch information
rebello95 committed Feb 26, 2024
1 parent 1eb6a95 commit eb12dd6
Show file tree
Hide file tree
Showing 17 changed files with 888 additions and 302 deletions.
4 changes: 3 additions & 1 deletion Libraries/Connect/Public/Interfaces/ConnectError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ extension ConnectError: Swift.Decodable {
public init(from decoder: Swift.Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.init(
code: Code.fromName(try container.decode(String.self, forKey: .code)),
code: try container
.decodeIfPresent(String.self, forKey: .code)
.map(Code.fromName) ?? .unknown,
message: try container.decodeIfPresent(String.self, forKey: .message),
exception: nil,
details: try container.decodeIfPresent([Detail].self, forKey: .details) ?? [],
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-print-directory
BIN := .tmp/bin
LICENSE_HEADER_YEAR_RANGE := 2022-2023
CONFORMANCE_PROTO_REF := 8ab24b156f5d3f8e7824b85732fa9765ab084879
CONFORMANCE_RUNNER_TAG := v1.0.0-rc2
CONFORMANCE_PROTO_REF := 9d4a2f7edaff9f184d110a612e45085aec3d9d36
CONFORMANCE_RUNNER_TAG := v1.0.0-rc3
EXAMPLES_PROTO_REF := e74547031f662f81a62f5e95ebaa9f7037e0c41b
LICENSE_HEADER_VERSION := v1.12.0
LICENSE_IGNORE := -e Package.swift \
Expand Down Expand Up @@ -78,8 +78,8 @@ $(BIN)/license-headers: Makefile
testconformance: ## Run all conformance tests
swift build -c release --product ConnectConformanceClient
mv ./.build/release/ConnectConformanceClient $(BIN)
PATH="$(abspath $(BIN)):$(PATH)" connectconformance -v --conf ./Tests/ConformanceClient/InvocationConfigs/urlsession.yaml --known-failing ./Tests/ConformanceClient/InvocationConfigs/opt-outs.txt --mode client $(BIN)/ConnectConformanceClient httpclient=urlsession
PATH="$(abspath $(BIN)):$(PATH)" connectconformance -v --conf ./Tests/ConformanceClient/InvocationConfigs/nio.yaml --known-failing ./Tests/ConformanceClient/InvocationConfigs/opt-outs.txt --mode client $(BIN)/ConnectConformanceClient httpclient=nio
PATH="$(abspath $(BIN)):$(PATH)" connectconformance -v --conf ./Tests/ConformanceClient/InvocationConfigs/urlsession.yaml --mode client $(BIN)/ConnectConformanceClient httpclient=urlsession
PATH="$(abspath $(BIN)):$(PATH)" connectconformance -v --conf ./Tests/ConformanceClient/InvocationConfigs/nio.yaml --mode client $(BIN)/ConnectConformanceClient httpclient=nio

.PHONY: testunit
testunit: ## Run all unit tests
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// For information on using the generated types, please see the documentation:
// https://github.com/apple/swift-protobuf/

// Copyright 2023 The Connect Authors
// Copyright 2023-2024 The Connect Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -298,6 +298,106 @@ extension Connectrpc_Conformance_V1_StreamType: CaseIterable {

#endif // swift(>=4.2)

enum Connectrpc_Conformance_V1_Code: SwiftProtobuf.Enum {
typealias RawValue = Int
case unspecified // = 0
case canceled // = 1
case unknown // = 2
case invalidArgument // = 3
case deadlineExceeded // = 4
case notFound // = 5
case alreadyExists // = 6
case permissionDenied // = 7
case resourceExhausted // = 8
case failedPrecondition // = 9
case aborted // = 10
case outOfRange // = 11
case unimplemented // = 12
case `internal` // = 13
case unavailable // = 14
case dataLoss // = 15
case unauthenticated // = 16
case UNRECOGNIZED(Int)

init() {
self = .unspecified
}

init?(rawValue: Int) {
switch rawValue {
case 0: self = .unspecified
case 1: self = .canceled
case 2: self = .unknown
case 3: self = .invalidArgument
case 4: self = .deadlineExceeded
case 5: self = .notFound
case 6: self = .alreadyExists
case 7: self = .permissionDenied
case 8: self = .resourceExhausted
case 9: self = .failedPrecondition
case 10: self = .aborted
case 11: self = .outOfRange
case 12: self = .unimplemented
case 13: self = .internal
case 14: self = .unavailable
case 15: self = .dataLoss
case 16: self = .unauthenticated
default: self = .UNRECOGNIZED(rawValue)
}
}

var rawValue: Int {
switch self {
case .unspecified: return 0
case .canceled: return 1
case .unknown: return 2
case .invalidArgument: return 3
case .deadlineExceeded: return 4
case .notFound: return 5
case .alreadyExists: return 6
case .permissionDenied: return 7
case .resourceExhausted: return 8
case .failedPrecondition: return 9
case .aborted: return 10
case .outOfRange: return 11
case .unimplemented: return 12
case .internal: return 13
case .unavailable: return 14
case .dataLoss: return 15
case .unauthenticated: return 16
case .UNRECOGNIZED(let i): return i
}
}

}

#if swift(>=4.2)

extension Connectrpc_Conformance_V1_Code: CaseIterable {
// The compiler won't synthesize support with the UNRECOGNIZED case.
static let allCases: [Connectrpc_Conformance_V1_Code] = [
.unspecified,
.canceled,
.unknown,
.invalidArgument,
.deadlineExceeded,
.notFound,
.alreadyExists,
.permissionDenied,
.resourceExhausted,
.failedPrecondition,
.aborted,
.outOfRange,
.unimplemented,
.internal,
.unavailable,
.dataLoss,
.unauthenticated,
]
}

#endif // swift(>=4.2)

/// Config defines the configuration for running conformance tests.
/// This enumerates all of the "flavors" of the test suite to run.
struct Connectrpc_Conformance_V1_Config {
Expand Down Expand Up @@ -333,31 +433,39 @@ struct Connectrpc_Conformance_V1_Config {
fileprivate var _features: Connectrpc_Conformance_V1_Features? = nil
}

/// TODO: we could probably model some of the constraints on what are valid vs.
/// invalid (i.e. conflicting/impossible) features using protovalidate rules
/// Features define the feature set that a client or server supports. They are
/// used to determine the server configurations and test cases that
/// will be run. They are defined in YAML files and are specified as part of the
/// --conf flag to the test runner.
struct Connectrpc_Conformance_V1_Features {
// SwiftProtobuf.Message conformance is added in an extension below. See the
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
// methods supported on all messages.

/// Supported HTTP versions.
/// If empty, HTTP 1.1 and HTTP/2 are assumed.
var versions: [Connectrpc_Conformance_V1_HTTPVersion] = []

/// Supported protocols.
/// If empty, all three are assumed: Connect, gRPC, and gRPC-Web.
var protocols: [Connectrpc_Conformance_V1_Protocol] = []

/// Supported codecs.
/// If empty, "proto" and "json" are assumed.
var codecs: [Connectrpc_Conformance_V1_Codec] = []

/// Supported compression algorithms.
/// If empty, "identity" and "gzip" are assumed.
var compressions: [Connectrpc_Conformance_V1_Compression] = []

/// Supported stream types.
/// If empty, all stream types are assumed. This is usually for
/// clients, since some client environments may not be able to
/// support certain kinds of streaming operations, especially
/// bidirectional streams.
var streamTypes: [Connectrpc_Conformance_V1_StreamType] = []

/// Whether H2C (unencrypted, non-TLS HTTP/2 over cleartext) is supported.
/// If absent, true is assumed.
var supportsH2C: Bool {
get {return _supportsH2C ?? false}
Expand All @@ -368,6 +476,7 @@ struct Connectrpc_Conformance_V1_Features {
/// Clears the value of `supportsH2C`. Subsequent reads from it will return its default value.
mutating func clearSupportsH2C() {self._supportsH2C = nil}

/// Whether TLS is supported.
/// If absent, true is assumed.
var supportsTls: Bool {
get {return _supportsTls ?? false}
Expand All @@ -378,6 +487,7 @@ struct Connectrpc_Conformance_V1_Features {
/// Clears the value of `supportsTls`. Subsequent reads from it will return its default value.
mutating func clearSupportsTls() {self._supportsTls = nil}

/// Whether the client supports TLS certificates.
/// If absent, false is assumed. This should not be set if
/// supports_tls is false.
var supportsTlsClientCerts: Bool {
Expand All @@ -389,6 +499,7 @@ struct Connectrpc_Conformance_V1_Features {
/// Clears the value of `supportsTlsClientCerts`. Subsequent reads from it will return its default value.
mutating func clearSupportsTlsClientCerts() {self._supportsTlsClientCerts = nil}

/// Whether trailers are supported.
/// If absent, true is assumed. If false, implies that gRPC protocol is not allowed.
var supportsTrailers: Bool {
get {return _supportsTrailers ?? false}
Expand All @@ -399,6 +510,7 @@ struct Connectrpc_Conformance_V1_Features {
/// Clears the value of `supportsTrailers`. Subsequent reads from it will return its default value.
mutating func clearSupportsTrailers() {self._supportsTrailers = nil}

/// Whether half duplex bidi streams are supported over HTTP/1.1.
/// If absent, false is assumed.
var supportsHalfDuplexBidiOverHTTP1: Bool {
get {return _supportsHalfDuplexBidiOverHTTP1 ?? false}
Expand All @@ -409,6 +521,7 @@ struct Connectrpc_Conformance_V1_Features {
/// Clears the value of `supportsHalfDuplexBidiOverHTTP1`. Subsequent reads from it will return its default value.
mutating func clearSupportsHalfDuplexBidiOverHTTP1() {self._supportsHalfDuplexBidiOverHTTP1 = nil}

/// Whether Connect via GET is supported.
/// If absent, true is assumed.
var supportsConnectGet: Bool {
get {return _supportsConnectGet ?? false}
Expand All @@ -419,16 +532,7 @@ struct Connectrpc_Conformance_V1_Features {
/// Clears the value of `supportsConnectGet`. Subsequent reads from it will return its default value.
mutating func clearSupportsConnectGet() {self._supportsConnectGet = nil}

/// If absent, false is assumed.
var requiresConnectVersionHeader: Bool {
get {return _requiresConnectVersionHeader ?? false}
set {_requiresConnectVersionHeader = newValue}
}
/// Returns true if `requiresConnectVersionHeader` has been explicitly set.
var hasRequiresConnectVersionHeader: Bool {return self._requiresConnectVersionHeader != nil}
/// Clears the value of `requiresConnectVersionHeader`. Subsequent reads from it will return its default value.
mutating func clearRequiresConnectVersionHeader() {self._requiresConnectVersionHeader = nil}

/// Whether a message receive limit is supported.
/// If absent, true is assumed.
var supportsMessageReceiveLimit: Bool {
get {return _supportsMessageReceiveLimit ?? false}
Expand All @@ -449,12 +553,13 @@ struct Connectrpc_Conformance_V1_Features {
fileprivate var _supportsTrailers: Bool? = nil
fileprivate var _supportsHalfDuplexBidiOverHTTP1: Bool? = nil
fileprivate var _supportsConnectGet: Bool? = nil
fileprivate var _requiresConnectVersionHeader: Bool? = nil
fileprivate var _supportsMessageReceiveLimit: Bool? = nil
}

/// TODO: we could probably model some of the constraints on what is a valid
/// vs. invalid config case using protovalidate rules
/// ConfigCase represents a single resolved configuration case. When tests are
/// run, the Config and the supported features therein are used to compute all
/// of the cases relevant to the implementation under test. These configuration
/// cases are then used to select which test cases are applicable.
struct Connectrpc_Conformance_V1_ConfigCase {
// SwiftProtobuf.Message conformance is added in an extension below. See the
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
Expand Down Expand Up @@ -524,6 +629,7 @@ extension Connectrpc_Conformance_V1_Protocol: @unchecked Sendable {}
extension Connectrpc_Conformance_V1_Codec: @unchecked Sendable {}
extension Connectrpc_Conformance_V1_Compression: @unchecked Sendable {}
extension Connectrpc_Conformance_V1_StreamType: @unchecked Sendable {}
extension Connectrpc_Conformance_V1_Code: @unchecked Sendable {}
extension Connectrpc_Conformance_V1_Config: @unchecked Sendable {}
extension Connectrpc_Conformance_V1_Features: @unchecked Sendable {}
extension Connectrpc_Conformance_V1_ConfigCase: @unchecked Sendable {}
Expand Down Expand Up @@ -583,6 +689,28 @@ extension Connectrpc_Conformance_V1_StreamType: SwiftProtobuf._ProtoNameProvidin
]
}

extension Connectrpc_Conformance_V1_Code: SwiftProtobuf._ProtoNameProviding {
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
0: .same(proto: "CODE_UNSPECIFIED"),
1: .same(proto: "CODE_CANCELED"),
2: .same(proto: "CODE_UNKNOWN"),
3: .same(proto: "CODE_INVALID_ARGUMENT"),
4: .same(proto: "CODE_DEADLINE_EXCEEDED"),
5: .same(proto: "CODE_NOT_FOUND"),
6: .same(proto: "CODE_ALREADY_EXISTS"),
7: .same(proto: "CODE_PERMISSION_DENIED"),
8: .same(proto: "CODE_RESOURCE_EXHAUSTED"),
9: .same(proto: "CODE_FAILED_PRECONDITION"),
10: .same(proto: "CODE_ABORTED"),
11: .same(proto: "CODE_OUT_OF_RANGE"),
12: .same(proto: "CODE_UNIMPLEMENTED"),
13: .same(proto: "CODE_INTERNAL"),
14: .same(proto: "CODE_UNAVAILABLE"),
15: .same(proto: "CODE_DATA_LOSS"),
16: .same(proto: "CODE_UNAUTHENTICATED"),
]
}

extension Connectrpc_Conformance_V1_Config: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
static let protoMessageName: String = _protobuf_package + ".Config"
static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
Expand Down Expand Up @@ -645,8 +773,7 @@ extension Connectrpc_Conformance_V1_Features: SwiftProtobuf.Message, SwiftProtob
9: .standard(proto: "supports_trailers"),
10: .standard(proto: "supports_half_duplex_bidi_over_http1"),
11: .standard(proto: "supports_connect_get"),
12: .standard(proto: "requires_connect_version_header"),
13: .standard(proto: "supports_message_receive_limit"),
12: .standard(proto: "supports_message_receive_limit"),
]

mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
Expand All @@ -666,8 +793,7 @@ extension Connectrpc_Conformance_V1_Features: SwiftProtobuf.Message, SwiftProtob
case 9: try { try decoder.decodeSingularBoolField(value: &self._supportsTrailers) }()
case 10: try { try decoder.decodeSingularBoolField(value: &self._supportsHalfDuplexBidiOverHTTP1) }()
case 11: try { try decoder.decodeSingularBoolField(value: &self._supportsConnectGet) }()
case 12: try { try decoder.decodeSingularBoolField(value: &self._requiresConnectVersionHeader) }()
case 13: try { try decoder.decodeSingularBoolField(value: &self._supportsMessageReceiveLimit) }()
case 12: try { try decoder.decodeSingularBoolField(value: &self._supportsMessageReceiveLimit) }()
default: break
}
}
Expand Down Expand Up @@ -711,11 +837,8 @@ extension Connectrpc_Conformance_V1_Features: SwiftProtobuf.Message, SwiftProtob
try { if let v = self._supportsConnectGet {
try visitor.visitSingularBoolField(value: v, fieldNumber: 11)
} }()
try { if let v = self._requiresConnectVersionHeader {
try visitor.visitSingularBoolField(value: v, fieldNumber: 12)
} }()
try { if let v = self._supportsMessageReceiveLimit {
try visitor.visitSingularBoolField(value: v, fieldNumber: 13)
try visitor.visitSingularBoolField(value: v, fieldNumber: 12)
} }()
try unknownFields.traverse(visitor: &visitor)
}
Expand All @@ -732,7 +855,6 @@ extension Connectrpc_Conformance_V1_Features: SwiftProtobuf.Message, SwiftProtob
if lhs._supportsTrailers != rhs._supportsTrailers {return false}
if lhs._supportsHalfDuplexBidiOverHTTP1 != rhs._supportsHalfDuplexBidiOverHTTP1 {return false}
if lhs._supportsConnectGet != rhs._supportsConnectGet {return false}
if lhs._requiresConnectVersionHeader != rhs._requiresConnectVersionHeader {return false}
if lhs._supportsMessageReceiveLimit != rhs._supportsMessageReceiveLimit {return false}
if lhs.unknownFields != rhs.unknownFields {return false}
return true
Expand Down
Loading

0 comments on commit eb12dd6

Please sign in to comment.