| 311 | } |
| 312 | |
| 313 | func TestReplacerDelete(t *testing.T) { |
| 314 | rep := Replacer{ |
| 315 | mapMutex: &sync.RWMutex{}, |
| 316 | static: map[string]any{ |
| 317 | "key1": "val1", |
| 318 | "key2": "val2", |
| 319 | "key3": "val3", |
| 320 | "key4": "val4", |
| 321 | }, |
| 322 | } |
| 323 | |
| 324 | startLen := len(rep.static) |
| 325 | |
| 326 | toDel := []string{ |
| 327 | "key2", "key4", |
| 328 | } |
| 329 | |
| 330 | for _, key := range toDel { |
| 331 | rep.Delete(key) |
| 332 | |
| 333 | // test if key is removed from static map |
| 334 | if _, ok := rep.static[key]; ok { |
| 335 | t.Errorf("Expected '%s' to be removed. It is still in static map.", key) |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | // check if static slice is smaller |
| 340 | expected := startLen - len(toDel) |
| 341 | actual := len(rep.static) |
| 342 | if len(rep.static) != expected { |
| 343 | t.Errorf("Expected length '%v' got length '%v'", expected, actual) |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | func TestReplacerMap(t *testing.T) { |
| 348 | rep := testReplacer() |