Skip to content

Commit cd8cb41

Browse files
authored
[repo/tests] use some utf8 string literals (open-telemetry#6107)
1 parent b508b84 commit cd8cb41

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/Implementation/Serializer/ProtobufSerializerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public void WriteStringWithTag_ASCIIString_WritesCorrectly()
246246
Assert.Equal(10, buffer[0]); // Tag
247247
Assert.Equal(5, buffer[1]); // Length
248248

249-
byte[] expectedContent = Encoding.ASCII.GetBytes("Hello");
249+
byte[] expectedContent = "Hello"u8.ToArray();
250250
byte[] actualContent = new byte[5];
251251
Array.Copy(buffer, 2, actualContent, 0, 5);
252252
Assert.True(expectedContent.SequenceEqual(actualContent));

test/OpenTelemetry.Tests/Internal/SelfDiagnosticsEventListenerTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_EnoughSpace()
191191

192192
// '\n' will be appended to the original string "abc" after EncodeInBuffer is called.
193193
// The byte where '\n' will be placed should not be touched within EncodeInBuffer, so it stays as '\0'.
194-
byte[] expected = Encoding.UTF8.GetBytes("abc\0");
194+
byte[] expected = "abc\0"u8.ToArray();
195195
AssertBufferOutput(expected, buffer, startPos, endPos + 1);
196196
}
197197

@@ -204,7 +204,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_NotEnoughSpaceForFullStr
204204
// It's a quick estimate by assumption that most Unicode characters takes up to 2 16-bit UTF-16 chars,
205205
// which can be up to 4 bytes when encoded in UTF-8.
206206
int endPos = SelfDiagnosticsEventListener.EncodeInBuffer("abc", false, buffer, startPos);
207-
byte[] expected = Encoding.UTF8.GetBytes("ab...\0");
207+
byte[] expected = "ab...\0"u8.ToArray();
208208
AssertBufferOutput(expected, buffer, startPos, endPos + 1);
209209
}
210210

@@ -214,7 +214,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_NotEvenSpaceForTruncated
214214
byte[] buffer = new byte[20];
215215
int startPos = buffer.Length - Ellipses.Length; // Just enough space for "...\n".
216216
int endPos = SelfDiagnosticsEventListener.EncodeInBuffer("abc", false, buffer, startPos);
217-
byte[] expected = Encoding.UTF8.GetBytes("...\0");
217+
byte[] expected = "...\0"u8.ToArray();
218218
AssertBufferOutput(expected, buffer, startPos, endPos + 1);
219219
}
220220

@@ -233,7 +233,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_IsParameter_EnoughSpace(
233233
byte[] buffer = new byte[20];
234234
int startPos = buffer.Length - EllipsesWithBrackets.Length - 6; // Just enough space for "abc" even if "...\n" need to be added.
235235
int endPos = SelfDiagnosticsEventListener.EncodeInBuffer("abc", true, buffer, startPos);
236-
byte[] expected = Encoding.UTF8.GetBytes("{abc}\0");
236+
byte[] expected = "{abc}\0"u8.ToArray();
237237
AssertBufferOutput(expected, buffer, startPos, endPos + 1);
238238
}
239239

@@ -243,7 +243,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_IsParameter_NotEnoughSpa
243243
byte[] buffer = new byte[20];
244244
int startPos = buffer.Length - EllipsesWithBrackets.Length - 5; // Just not space for "...\n".
245245
int endPos = SelfDiagnosticsEventListener.EncodeInBuffer("abc", true, buffer, startPos);
246-
byte[] expected = Encoding.UTF8.GetBytes("{ab...}\0");
246+
byte[] expected = "{ab...}\0"u8.ToArray();
247247
AssertBufferOutput(expected, buffer, startPos, endPos + 1);
248248
}
249249

@@ -253,7 +253,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_IsParameter_NotEvenSpace
253253
byte[] buffer = new byte[20];
254254
int startPos = buffer.Length - EllipsesWithBrackets.Length; // Just enough space for "{...}\n".
255255
int endPos = SelfDiagnosticsEventListener.EncodeInBuffer("abc", true, buffer, startPos);
256-
byte[] expected = Encoding.UTF8.GetBytes("{...}\0");
256+
byte[] expected = "{...}\0"u8.ToArray();
257257
AssertBufferOutput(expected, buffer, startPos, endPos + 1);
258258
}
259259

test/OpenTelemetry.Tests/Trace/SpanContextTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ namespace OpenTelemetry.Trace.Tests;
88

99
public class SpanContextTest
1010
{
11-
private static readonly byte[] FirstTraceIdBytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte)'a' };
12-
private static readonly byte[] SecondTraceIdBytes = { 0, 0, 0, 0, 0, 0, 0, (byte)'0', 0, 0, 0, 0, 0, 0, 0, 0 };
13-
private static readonly byte[] FirstSpanIdBytes = { 0, 0, 0, 0, 0, 0, 0, (byte)'a' };
14-
private static readonly byte[] SecondSpanIdBytes = { (byte)'0', 0, 0, 0, 0, 0, 0, 0 };
11+
private static readonly byte[] FirstTraceIdBytes = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0a"u8.ToArray();
12+
private static readonly byte[] SecondTraceIdBytes = "\0\0\0\0\0\0\00\0\0\0\0\0\0\0\0"u8.ToArray();
13+
private static readonly byte[] FirstSpanIdBytes = "\0\0\0\0\0\0\0a"u8.ToArray();
14+
private static readonly byte[] SecondSpanIdBytes = "0\0\0\0\0\0\0\0"u8.ToArray();
1515

1616
private static readonly SpanContext First =
1717
new(

0 commit comments

Comments
 (0)