|
4 | 4 | package pprofile |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "errors" |
7 | 8 | "testing" |
8 | 9 |
|
9 | 10 | "github.com/stretchr/testify/assert" |
@@ -122,6 +123,87 @@ func TestMappingSwitchDictionary(t *testing.T) { |
122 | 123 | return d |
123 | 124 | }(), |
124 | 125 | }, |
| 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 | + }, |
125 | 207 | } { |
126 | 208 | t.Run(tt.name, func(t *testing.T) { |
127 | 209 | m := tt.mapping |
|
0 commit comments