File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
Tests/W3CTraceContextTests Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1010// SPDX-License-Identifier: Apache-2.0
1111//
1212//===----------------------------------------------------------------------===//
13+
1314public enum W3C { }
15+
16+ extension W3C {
17+ public struct TraceContext : Equatable {
18+ public let parent : TraceParent
19+
20+ public init ( parent: TraceParent ) {
21+ self . parent = parent
22+ }
23+
24+ public init ? ( parent parentRawValue: String ) {
25+ guard let parent = TraceParent ( rawValue: parentRawValue) else { return nil }
26+ self . parent = parent
27+ }
28+ }
29+ }
Original file line number Diff line number Diff line change 1+ //===----------------------------------------------------------------------===//
2+ //
3+ // This source file is part of the Swift W3C Trace Context open source project
4+ //
5+ // Copyright (c) 2020 Moritz Lang and the Swift W3C Trace Context project authors
6+ // Licensed under Apache License v2.0
7+ //
8+ // See LICENSE.txt for license information
9+ //
10+ // SPDX-License-Identifier: Apache-2.0
11+ //
12+ //===----------------------------------------------------------------------===//
13+
14+ import W3CTraceContext
15+ import XCTest
16+
17+ final class TraceContextTests : XCTestCase {
18+ func testInitWithValidRawValues( ) {
19+ let traceParentRawValue = " 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01 "
20+
21+ guard let traceContext = W3C . TraceContext ( parent: traceParentRawValue) else {
22+ XCTFail ( " Could not decode valid trace context " )
23+ return
24+ }
25+
26+ XCTAssertEqual (
27+ traceContext,
28+ W3C . TraceContext (
29+ parent: W3C . TraceParent (
30+ traceID: " 0af7651916cd43dd8448eb211c80319c " ,
31+ parentID: " b7ad6b7169203331 " ,
32+ traceFlags: " 01 "
33+ )
34+ )
35+ )
36+ }
37+
38+ func testInitWithInvalidTraceParent( ) {
39+ XCTAssertNil ( W3C . TraceContext ( parent: " invalid " ) )
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments