Skip to content

Commit 2ff423f

Browse files
committed
Add test case to check out-of-range index detection
1 parent 93be1c2 commit 2ff423f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pdata/pprofile/attributes_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,16 @@ func testPutAttribute(t *testing.T, record attributable) {
8686

8787
// Add a negative index to the record.
8888
record.AttributeIndices().Append(-1)
89-
// Try putting a new attribute, make sure it fails, and that table/indices didn't change.
9089
tableLen := table.Len()
9190
indicesLen := record.AttributeIndices().Len()
91+
// Try putting a new attribute, make sure it fails, and that table/indices didn't change.
92+
require.Error(t, PutAttribute(table, record, "newKey", pcommon.NewValueStr("value")))
93+
require.Equal(t, tableLen, table.Len())
94+
require.Equal(t, indicesLen, record.AttributeIndices().Len())
95+
96+
// Set the last index to the table length, which is out of range.
97+
record.AttributeIndices().SetAt(indicesLen-1, int32(tableLen))
98+
// Try putting a new attribute, make sure it fails, and that table/indices didn't change.
9299
require.Error(t, PutAttribute(table, record, "newKey", pcommon.NewValueStr("value")))
93100
require.Equal(t, tableLen, table.Len())
94101
require.Equal(t, indicesLen, record.AttributeIndices().Len())

0 commit comments

Comments
 (0)