Skip to content

Commit 9ae7ccc

Browse files
committed
add missing tests to mapping
1 parent 1e2b9aa commit 9ae7ccc

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

pdata/pprofile/mapping_test.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package pprofile
55

66
import (
7+
"errors"
78
"testing"
89

910
"github.com/stretchr/testify/assert"
@@ -122,6 +123,87 @@ func TestMappingSwitchDictionary(t *testing.T) {
122123
return d
123124
}(),
124125
},
126+
{
127+
name: "with a filename index that does not match anything",
128+
mapping: func() Mapping {
129+
m := NewMapping()
130+
m.SetFilenameStrindex(1)
131+
return m
132+
}(),
133+
134+
src: NewProfilesDictionary(),
135+
dst: NewProfilesDictionary(),
136+
137+
wantMapping: func() Mapping {
138+
m := NewMapping()
139+
m.SetFilenameStrindex(1)
140+
return m
141+
}(),
142+
wantDictionary: NewProfilesDictionary(),
143+
wantErr: errors.New("invalid filename index 1"),
144+
},
145+
{
146+
name: "with an existing attribute",
147+
mapping: func() Mapping {
148+
m := NewMapping()
149+
m.AttributeIndices().Append(1)
150+
return m
151+
}(),
152+
153+
src: func() ProfilesDictionary {
154+
d := NewProfilesDictionary()
155+
d.StringTable().Append("", "test")
156+
157+
d.AttributeTable().AppendEmpty()
158+
a := d.AttributeTable().AppendEmpty()
159+
a.SetKeyStrindex(1)
160+
161+
return d
162+
}(),
163+
dst: func() ProfilesDictionary {
164+
d := NewProfilesDictionary()
165+
d.StringTable().Append("", "foo")
166+
167+
d.AttributeTable().AppendEmpty()
168+
d.AttributeTable().AppendEmpty()
169+
return d
170+
}(),
171+
172+
wantMapping: func() Mapping {
173+
m := NewMapping()
174+
m.AttributeIndices().Append(2)
175+
return m
176+
}(),
177+
wantDictionary: func() ProfilesDictionary {
178+
d := NewProfilesDictionary()
179+
d.StringTable().Append("", "foo", "test")
180+
181+
d.AttributeTable().AppendEmpty()
182+
d.AttributeTable().AppendEmpty()
183+
a := d.AttributeTable().AppendEmpty()
184+
a.SetKeyStrindex(2)
185+
return d
186+
}(),
187+
},
188+
{
189+
name: "with an attribute index that does not match anything",
190+
mapping: func() Mapping {
191+
m := NewMapping()
192+
m.AttributeIndices().Append(1)
193+
return m
194+
}(),
195+
196+
src: NewProfilesDictionary(),
197+
dst: NewProfilesDictionary(),
198+
199+
wantMapping: func() Mapping {
200+
m := NewMapping()
201+
m.AttributeIndices().Append(1)
202+
return m
203+
}(),
204+
wantDictionary: NewProfilesDictionary(),
205+
wantErr: errors.New("invalid attribute index 1"),
206+
},
125207
} {
126208
t.Run(tt.name, func(t *testing.T) {
127209
m := tt.mapping

0 commit comments

Comments
 (0)