MCPcopy Index your code
hub / github.com/mpolden/echoip / TestCacheResize

Function TestCacheResize

http/cache_test.go:63–87  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestCacheResize(t *testing.T) {
64 c := NewCache(10)
65 for i := 1; i <= 20; i++ {
66 ip := net.ParseIP(fmt.Sprintf("192.0.2.%d", i))
67 r := Response{IP: ip}
68 c.Set(ip, r)
69 }
70 if got, want := len(c.entries), 10; got != want {
71 t.Errorf("want %d entries, got %d", want, got)
72 }
73 if got, want := c.evictions, uint64(10); got != want {
74 t.Errorf("want %d evictions, got %d", want, got)
75 }
76 if err := c.Resize(5); err != nil {
77 t.Fatal(err)
78 }
79 if got, want := c.evictions, uint64(0); got != want {
80 t.Errorf("want %d evictions, got %d", want, got)
81 }
82 r := Response{IP: net.ParseIP("192.0.2.42")}
83 c.Set(r.IP, r)
84 if got, want := len(c.entries), 5; got != want {
85 t.Errorf("want %d entries, got %d", want, got)
86 }
87}

Callers

nothing calls this directly

Calls 3

SetMethod · 0.95
ResizeMethod · 0.95
NewCacheFunction · 0.85

Tested by

no test coverage detected