mirror of
https://github.com/charmbracelet/crush.git
synced 2026-05-30 18:47:33 +00:00
* fix(ui): clear image cache when FilePicker closes to prevent unbounded memory growth * fix(ui): only reset image cache on FilePicker close, not on new session * fix(ui): reset image cache after Dialog close * fix(ui): rename image.Reset to image.ResetCache for clarity
47 lines
816 B
Go
47 lines
816 B
Go
package image
|
|
|
|
import (
|
|
"image"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestResetCache(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
cachedMutex.Lock()
|
|
cachedImages[imageKey{id: "a", cols: 10, rows: 10}] = cachedImage{
|
|
img: image.NewRGBA(image.Rect(0, 0, 1, 1)),
|
|
cols: 10,
|
|
rows: 10,
|
|
}
|
|
cachedImages[imageKey{id: "b", cols: 20, rows: 20}] = cachedImage{
|
|
img: image.NewRGBA(image.Rect(0, 0, 1, 1)),
|
|
cols: 20,
|
|
rows: 20,
|
|
}
|
|
cachedMutex.Unlock()
|
|
|
|
ResetCache()
|
|
|
|
cachedMutex.RLock()
|
|
length := len(cachedImages)
|
|
cachedMutex.RUnlock()
|
|
|
|
require.Equal(t, 0, length)
|
|
}
|
|
|
|
func TestResetIdempotent(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Calling Reset on an empty cache should not panic.
|
|
ResetCache()
|
|
|
|
cachedMutex.RLock()
|
|
length := len(cachedImages)
|
|
cachedMutex.RUnlock()
|
|
|
|
require.Equal(t, 0, length)
|
|
}
|