|
11 | 11 | // |
12 | 12 | //===----------------------------------------------------------------------===// |
13 | 13 |
|
14 | | -@testable import W3CTraceContext |
| 14 | +import W3CTraceContext |
15 | 15 | import XCTest |
16 | 16 |
|
17 | 17 | final class TraceParentRawRepresentableTests: XCTestCase { |
18 | | - // MARK: - Trace Parent - |
| 18 | + // MARK: - Encoding |
| 19 | + |
| 20 | + func testEncodesToValidRawValue() { |
| 21 | + let traceParent = W3C.TraceParent( |
| 22 | + traceID: "0af7651916cd43dd8448eb211c80319c", |
| 23 | + parentID: "b7ad6b7169203331", |
| 24 | + traceFlags: "01" |
| 25 | + ) |
| 26 | + |
| 27 | + XCTAssertEqual(traceParent.rawValue, "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01") |
| 28 | + } |
| 29 | + |
| 30 | + // MARK: - Decoding |
19 | 31 |
|
20 | 32 | func testDecodeValidTraceParentStringWithSampledFlag() { |
21 | 33 | let rawValue = "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01" |
@@ -47,16 +59,6 @@ final class TraceParentRawRepresentableTests: XCTestCase { |
47 | 59 | XCTAssertFalse(traceParent.sampled) |
48 | 60 | } |
49 | 61 |
|
50 | | - func testEncodesToValidRawValue() { |
51 | | - let traceParent = W3C.TraceParent( |
52 | | - traceID: "0af7651916cd43dd8448eb211c80319c", |
53 | | - parentID: "b7ad6b7169203331", |
54 | | - traceFlags: "01" |
55 | | - ) |
56 | | - |
57 | | - XCTAssertEqual(traceParent.rawValue, "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01") |
58 | | - } |
59 | | - |
60 | 62 | func testDecodeFailsWithTooLongRawValue() { |
61 | 63 | let rawValue = String(repeating: "42", count: 1000) |
62 | 64 | XCTAssertUninitializedTraceParent(rawValue) |
@@ -117,7 +119,37 @@ final class TraceParentRawRepresentableTests: XCTestCase { |
117 | 119 | XCTAssertUninitializedTraceParent(rawValue) |
118 | 120 | } |
119 | 121 |
|
120 | | - // TODO: Trace State |
| 122 | + // MARK: - Equatable |
| 123 | + |
| 124 | + func testNonEqualTraceID() { |
| 125 | + let parent1 = W3C.TraceParent(rawValue: "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01") |
| 126 | + let parent2 = W3C.TraceParent(rawValue: "00-12345678912345678912345678912345-b7ad6b7169203331-01") |
| 127 | + |
| 128 | + XCTAssertNotNil(parent1) |
| 129 | + XCTAssertNotNil(parent2) |
| 130 | + |
| 131 | + XCTAssertNotEqual(parent1, parent2) |
| 132 | + } |
| 133 | + |
| 134 | + func testNonEqualParentID() { |
| 135 | + let parent1 = W3C.TraceParent(rawValue: "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01") |
| 136 | + let parent2 = W3C.TraceParent(rawValue: "00-0af7651916cd43dd8448eb211c80319c-1234567891234567-01") |
| 137 | + |
| 138 | + XCTAssertNotNil(parent1) |
| 139 | + XCTAssertNotNil(parent2) |
| 140 | + |
| 141 | + XCTAssertNotEqual(parent1, parent2) |
| 142 | + } |
| 143 | + |
| 144 | + func testNonEqualTraceFlags() { |
| 145 | + let parent1 = W3C.TraceParent(rawValue: "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-00") |
| 146 | + let parent2 = W3C.TraceParent(rawValue: "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01") |
| 147 | + |
| 148 | + XCTAssertNotNil(parent1) |
| 149 | + XCTAssertNotNil(parent2) |
| 150 | + |
| 151 | + XCTAssertNotEqual(parent1, parent2) |
| 152 | + } |
121 | 153 | } |
122 | 154 |
|
123 | 155 | private func XCTAssertUninitializedTraceParent(_ rawValue: String, file: StaticString = #file, line: UInt = #line) { |
|
0 commit comments