File tree Expand file tree Collapse file tree 1 file changed +4
-10
lines changed
Tests/AWSLambdaRuntimeTests Expand file tree Collapse file tree 1 file changed +4
-10
lines changed Original file line number Diff line number Diff line change @@ -16,29 +16,23 @@ import Testing
16
16
17
17
@testable import AWSLambdaRuntime
18
18
19
- #if canImport(FoundationEssentials)
20
- import FoundationEssentials
21
- #else
22
- import Foundation
23
- #endif
24
-
25
19
struct UtilsTest {
26
20
@Test
27
21
func testGenerateXRayTraceID( ) {
28
- // the time and identifier should be in hexadecimal digits
29
- let invalidCharacters = CharacterSet ( charactersIn: " abcdef0123456789 " ) . inverted
30
22
let numTests = 1000
31
23
var values = Set < String > ( )
32
24
for _ in 0 ..< numTests {
25
+ // the time and identifier should be in hexadecimal digits
26
+ let allowedCharacters = " 0123456789abcdef "
33
27
// check the format, see https://docs.aws.amazon.com/xray/latest/devguide/xray-api-sendingdata.html#xray-api-traceids)
34
28
let traceId = AmazonHeaders . generateXRayTraceID ( )
35
29
let segments = traceId. split ( separator: " - " )
36
30
#expect( segments. count == 3 )
37
31
#expect( segments [ 0 ] == " 1 " )
38
32
#expect( segments [ 1 ] . count == 8 )
39
- #expect( segments [ 1 ] . rangeOfCharacter ( from: invalidCharacters) == nil )
40
33
#expect( segments [ 2 ] . count == 24 )
41
- #expect( segments [ 2 ] . rangeOfCharacter ( from: invalidCharacters) == nil )
34
+ #expect( segments [ 1 ] . allSatisfy { allowedCharacters. contains ( $0) } )
35
+ #expect( segments [ 2 ] . allSatisfy { allowedCharacters. contains ( $0) } )
42
36
values. insert ( traceId)
43
37
}
44
38
// check that the generated values are different
You can’t perform that action at this time.
0 commit comments