Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TracingUUID toString string format #1311

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/Datadog/Tracing/UUIDs/TracingUUID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ internal struct TracingUUID: Equatable, Hashable {
case .hexadecimal:
return String(rawValue, radix: 16)
case .hexadecimal16Chars:
return String(format: "%016x", rawValue)
return String(format: "%016llx", rawValue)
case .hexadecimal32Chars:
return String(format: "%032x", rawValue)
return String(format: "%032llx", rawValue)
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions Tests/DatadogTests/Datadog/Tracing/UUIDs/TracingUUIDTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@ class UUIDTests: XCTestCase {
XCTAssertEqual(TracingUUID(rawValue: .max).toString(.hexadecimal), "ffffffffffffffff")
}

func testTo16CharHexadecimalStringConversion() {
XCTAssertEqual(TracingUUID(rawValue: 0).toString(.hexadecimal16Chars), "0000000000000000")
XCTAssertEqual(TracingUUID(rawValue: 1).toString(.hexadecimal16Chars), "0000000000000001")
XCTAssertEqual(TracingUUID(rawValue: 15).toString(.hexadecimal16Chars), "000000000000000f")
XCTAssertEqual(TracingUUID(rawValue: 16).toString(.hexadecimal16Chars), "0000000000000010")
XCTAssertEqual(TracingUUID(rawValue: 123).toString(.hexadecimal16Chars), "000000000000007b")
XCTAssertEqual(TracingUUID(rawValue: 123_456).toString(.hexadecimal16Chars), "000000000001e240")
XCTAssertEqual(TracingUUID(rawValue: .max).toString(.hexadecimal16Chars), "ffffffffffffffff")
}

func testTo32CharHexadecimalStringConversion() {
XCTAssertEqual(TracingUUID(rawValue: 0).toString(.hexadecimal32Chars), "00000000000000000000000000000000")
XCTAssertEqual(TracingUUID(rawValue: 1).toString(.hexadecimal32Chars), "00000000000000000000000000000001")
XCTAssertEqual(TracingUUID(rawValue: 15).toString(.hexadecimal32Chars), "0000000000000000000000000000000f")
XCTAssertEqual(TracingUUID(rawValue: 16).toString(.hexadecimal32Chars), "00000000000000000000000000000010")
XCTAssertEqual(TracingUUID(rawValue: 123).toString(.hexadecimal32Chars), "0000000000000000000000000000007b")
XCTAssertEqual(TracingUUID(rawValue: 123_456).toString(.hexadecimal32Chars), "0000000000000000000000000001e240")
XCTAssertEqual(TracingUUID(rawValue: .max).toString(.hexadecimal32Chars), "0000000000000000ffffffffffffffff")
}

func testToDecimalStringConversion() {
XCTAssertEqual(TracingUUID(rawValue: 0).toString(.decimal), "0")
XCTAssertEqual(TracingUUID(rawValue: 1).toString(.decimal), "1")
Expand Down