@@ -0,0 +1,46 @@
1+package image
2+
3+import (
4+ "image"
5+ "testing"
6+
7+ "github.com/stretchr/testify/require"
8+)
9+
10+func TestResetCache(t *testing.T) {
11+ t.Parallel()
12+
13+ cachedMutex.Lock()
14+ cachedImages[imageKey{id: "a", cols: 10, rows: 10}] = cachedImage{
15+ img: image.NewRGBA(image.Rect(0, 0, 1, 1)),
16+ cols: 10,
17+ rows: 10,
18+ }
19+ cachedImages[imageKey{id: "b", cols: 20, rows: 20}] = cachedImage{
20+ img: image.NewRGBA(image.Rect(0, 0, 1, 1)),
21+ cols: 20,
22+ rows: 20,
23+ }
24+ cachedMutex.Unlock()
25+
26+ ResetCache()
27+
28+ cachedMutex.RLock()
29+ length := len(cachedImages)
30+ cachedMutex.RUnlock()
31+
32+ require.Equal(t, 0, length)
33+}
34+
35+func TestResetIdempotent(t *testing.T) {
36+ t.Parallel()
37+
38+ // Calling Reset on an empty cache should not panic.
39+ ResetCache()
40+
41+ cachedMutex.RLock()
42+ length := len(cachedImages)
43+ cachedMutex.RUnlock()
44+
45+ require.Equal(t, 0, length)
46+}