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/screenshot/cache_test.go

37 lines
875 B

package screenshot
import (
"context"
"testing"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestInmemCacheService(t *testing.T) {
s := NewInmemCacheService(time.Second, prometheus.DefaultRegisterer)
ctx := context.Background()
opts := ScreenshotOptions{DashboardUID: "foo", PanelID: 1}
// should be a miss
actual, ok := s.Get(ctx, opts)
assert.False(t, ok)
assert.Nil(t, actual)
// should be a hit
expected := Screenshot{Path: "panel.png"}
require.NoError(t, s.Set(ctx, opts, &expected))
actual, ok = s.Get(ctx, opts)
assert.True(t, ok)
assert.Equal(t, expected, *actual)
// wait 1s and the cached screenshot should have expired
<-time.After(time.Second)
// should be a miss
actual, ok = s.Get(ctx, opts)
assert.False(t, ok)
assert.Nil(t, actual)
}