(t *testing.T)
| 1200 | } |
| 1201 | |
| 1202 | func TestRemove(t *testing.T) { |
| 1203 | var testcases = []struct { |
| 1204 | desc string |
| 1205 | samples []*Sample |
| 1206 | removeKey string |
| 1207 | wantLabels []map[string][]string |
| 1208 | }{ |
| 1209 | { |
| 1210 | desc: "some samples have label already", |
| 1211 | samples: []*Sample{ |
| 1212 | { |
| 1213 | Location: []*Location{cpuL[0]}, |
| 1214 | Value: []int64{1000}, |
| 1215 | }, |
| 1216 | { |
| 1217 | Location: []*Location{cpuL[0]}, |
| 1218 | Value: []int64{1000}, |
| 1219 | Label: map[string][]string{ |
| 1220 | "key1": {"value1", "value2", "value3"}, |
| 1221 | "key2": {"value1"}, |
| 1222 | }, |
| 1223 | }, |
| 1224 | { |
| 1225 | Location: []*Location{cpuL[0]}, |
| 1226 | Value: []int64{1000}, |
| 1227 | Label: map[string][]string{ |
| 1228 | "key1": {"value2"}, |
| 1229 | }, |
| 1230 | }, |
| 1231 | }, |
| 1232 | removeKey: "key1", |
| 1233 | wantLabels: []map[string][]string{ |
| 1234 | {}, |
| 1235 | {"key2": {"value1"}}, |
| 1236 | {}, |
| 1237 | }, |
| 1238 | }, |
| 1239 | } |
| 1240 | |
| 1241 | for _, tc := range testcases { |
| 1242 | t.Run(tc.desc, func(t *testing.T) { |
| 1243 | profile := testProfile1.Copy() |
| 1244 | profile.Sample = tc.samples |
| 1245 | profile.RemoveLabel(tc.removeKey) |
| 1246 | if got, want := len(profile.Sample), len(tc.wantLabels); got != want { |
| 1247 | t.Fatalf("got %v samples, want %v samples", got, want) |
| 1248 | } |
| 1249 | for i, sample := range profile.Sample { |
| 1250 | wantLabels := tc.wantLabels[i] |
| 1251 | if got, want := len(sample.Label), len(wantLabels); got != want { |
| 1252 | t.Errorf("got %v label keys for sample %v, want %v", got, i, want) |
| 1253 | continue |
| 1254 | } |
| 1255 | for wantKey, wantValues := range wantLabels { |
| 1256 | if gotValues, ok := sample.Label[wantKey]; ok { |
| 1257 | if !reflect.DeepEqual(gotValues, wantValues) { |
| 1258 | t.Errorf("for key %s, got values %v, want values %v", wantKey, gotValues, wantValues) |
| 1259 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…