Files
swift-aws-lambda-runtime/Tests/AWSLambdaRuntimeCoreTests/UtilsTest.swift
T
ab8166a39d [CI] Add GHA CI and release flow (#340)
Co-authored-by: Fabian Fett <fabianfett@apple.com>
Co-authored-by: Sébastien Stormacq <sebastien.stormacq@gmail.com>
Co-authored-by: Mahdi Bahrami <github@mahdibm.com>
2024-08-26 16:36:07 +02:00

41 lines
1.6 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftAWSLambdaRuntime open source project
//
// Copyright (c) 2017-2018 Apple Inc. and the SwiftAWSLambdaRuntime project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import XCTest
@testable import AWSLambdaRuntimeCore
class UtilsTest: XCTestCase {
func testGenerateXRayTraceID() {
// the time and identifier should be in hexadecimal digits
let invalidCharacters = CharacterSet(charactersIn: "abcdef0123456789").inverted
let numTests = 1000
var values = Set<String>()
for _ in 0..<numTests {
// check the format, see https://docs.aws.amazon.com/xray/latest/devguide/xray-api-sendingdata.html#xray-api-traceids)
let traceId = AmazonHeaders.generateXRayTraceID()
let segments = traceId.split(separator: "-")
XCTAssertEqual(3, segments.count)
XCTAssertEqual("1", segments[0])
XCTAssertEqual(8, segments[1].count)
XCTAssertNil(segments[1].rangeOfCharacter(from: invalidCharacters))
XCTAssertEqual(24, segments[2].count)
XCTAssertNil(segments[2].rangeOfCharacter(from: invalidCharacters))
values.insert(traceId)
}
// check that the generated values are different
XCTAssertEqual(values.count, numTests)
}
}