MCPcopy
hub / github.com/caddyserver/caddy / TestReplacerDelete

Function TestReplacerDelete

replacer_test.go:313–345  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

311}
312
313func 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
347func TestReplacerMap(t *testing.T) {
348 rep := testReplacer()

Callers

nothing calls this directly

Calls 1

DeleteMethod · 0.95

Tested by

no test coverage detected