The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/services/ngalert/image/cache_test.go

38 lines
907 B

package image
import (
"context"
"testing"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/services/ngalert/models"
)
func TestInmemCacheService(t *testing.T) {
s := NewInmemCacheService(time.Second, prometheus.DefaultRegisterer)
ctx := context.Background()
// should be a miss
actual, ok := s.Get(ctx, "test")
assert.False(t, ok)
assert.Equal(t, models.Image{}, actual)
// should be a hit
expected := models.Image{Path: "test.png"}
require.NoError(t, s.Set(ctx, "test", expected))
actual, ok = s.Get(ctx, "test")
assert.True(t, ok)
assert.Equal(t, expected, actual)
// wait 1s and the cached image should have expired
<-time.After(time.Second)
// should be a miss
actual, ok = s.Get(ctx, "test")
assert.False(t, ok)
assert.Equal(t, models.Image{}, actual)
}