Skip to content

Commit a32a23d

Browse files
committed
Test every exisiting record type
1 parent 94550e8 commit a32a23d

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

pdata/pprofile/attributes_test.go

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,45 +44,61 @@ func TestFromAttributeIndices(t *testing.T) {
4444
assert.Equal(t, attrs.AsRaw(), m)
4545
}
4646

47-
func TestPutAttribute(t *testing.T) {
47+
func testPutAttribute(t *testing.T, record attributable) {
4848
table := NewAttributeTableSlice()
49-
indices := NewProfile()
5049

5150
// Put a first attribute.
52-
require.NoError(t, PutAttribute(table, indices, "hello", pcommon.NewValueStr("world")))
51+
require.NoError(t, PutAttribute(table, record, "hello", pcommon.NewValueStr("world")))
5352
assert.Equal(t, 1, table.Len())
54-
assert.Equal(t, []int32{0}, indices.AttributeIndices().AsRaw())
53+
assert.Equal(t, []int32{0}, record.AttributeIndices().AsRaw())
5554

5655
// Put an attribute, same key, same value.
5756
// This should be a no-op.
58-
require.NoError(t, PutAttribute(table, indices, "hello", pcommon.NewValueStr("world")))
57+
require.NoError(t, PutAttribute(table, record, "hello", pcommon.NewValueStr("world")))
5958
assert.Equal(t, 1, table.Len())
60-
assert.Equal(t, []int32{0}, indices.AttributeIndices().AsRaw())
59+
assert.Equal(t, []int32{0}, record.AttributeIndices().AsRaw())
6160

6261
// Put an attribute, same key, different value.
6362
// This updates the index and adds to the table.
6463
fmt.Printf("test\n")
65-
require.NoError(t, PutAttribute(table, indices, "hello", pcommon.NewValueStr("world2")))
64+
require.NoError(t, PutAttribute(table, record, "hello", pcommon.NewValueStr("world2")))
6665
assert.Equal(t, 2, table.Len())
67-
assert.Equal(t, []int32{1}, indices.AttributeIndices().AsRaw())
66+
assert.Equal(t, []int32{1}, record.AttributeIndices().AsRaw())
6867

6968
// Put an attribute that already exists in the table.
7069
// This updates the index and does not add to the table.
71-
require.NoError(t, PutAttribute(table, indices, "hello", pcommon.NewValueStr("world")))
70+
require.NoError(t, PutAttribute(table, record, "hello", pcommon.NewValueStr("world")))
7271
assert.Equal(t, 2, table.Len())
73-
assert.Equal(t, []int32{0}, indices.AttributeIndices().AsRaw())
72+
assert.Equal(t, []int32{0}, record.AttributeIndices().AsRaw())
7473

7574
// Put a new attribute.
7675
// This adds an index and adds to the table.
77-
require.NoError(t, PutAttribute(table, indices, "good", pcommon.NewValueStr("day")))
76+
require.NoError(t, PutAttribute(table, record, "good", pcommon.NewValueStr("day")))
7877
assert.Equal(t, 3, table.Len())
79-
assert.Equal(t, []int32{0, 2}, indices.AttributeIndices().AsRaw())
78+
assert.Equal(t, []int32{0, 2}, record.AttributeIndices().AsRaw())
8079

8180
// Add multiple distinct attributes.
8281
for i := range 100 {
83-
require.NoError(t, PutAttribute(table, indices, fmt.Sprintf("key_%d", i), pcommon.NewValueStr("day")))
82+
require.NoError(t, PutAttribute(table, record, fmt.Sprintf("key_%d", i), pcommon.NewValueStr("day")))
8483
assert.Equal(t, i+4, table.Len())
85-
assert.Equal(t, i+3, indices.AttributeIndices().Len())
84+
assert.Equal(t, i+3, record.AttributeIndices().Len())
85+
}
86+
}
87+
88+
func TestPutAttribute(t *testing.T) {
89+
// Test every existing record type.
90+
for _, tt := range []struct {
91+
name string
92+
attr attributable
93+
}{
94+
{"Profile", NewProfile()},
95+
{"Sample", NewSample()},
96+
{"Mapping", NewMapping()},
97+
{"Location", NewLocation()},
98+
} {
99+
t.Run(tt.name, func(t *testing.T) {
100+
testPutAttribute(t, tt.attr)
101+
})
86102
}
87103
}
88104

0 commit comments

Comments
 (0)