mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 05:29:42 -06:00
f58a63b2df
* use time mocks in queryhistory to speed up tests * remove comments
53 lines
1.9 KiB
Go
53 lines
1.9 KiB
Go
package queryhistory
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/grafana/grafana/pkg/web"
|
|
)
|
|
|
|
func TestIntegrationDeleteStaleQueryFromQueryHistory(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skipping integration test")
|
|
}
|
|
testScenarioWithQueryInQueryHistory(t, "Stale query history can be deleted",
|
|
func(t *testing.T, sc scenarioContext) {
|
|
olderThan := sc.service.now().Unix() + 60
|
|
rowsDeleted, err := sc.service.DeleteStaleQueriesInQueryHistory(context.Background(), olderThan)
|
|
require.NoError(t, err)
|
|
require.Equal(t, 1, rowsDeleted)
|
|
})
|
|
|
|
testScenarioWithQueryInQueryHistory(t, "Stale single starred query history can not be deleted",
|
|
func(t *testing.T, sc scenarioContext) {
|
|
sc.ctx.Req = web.SetURLParams(sc.ctx.Req, map[string]string{":uid": sc.initialResult.Result.UID})
|
|
resp := sc.service.starHandler(sc.reqContext)
|
|
require.Equal(t, 200, resp.Status())
|
|
|
|
olderThan := sc.service.now().Unix() + 60
|
|
rowsDeleted, err := sc.service.DeleteStaleQueriesInQueryHistory(context.Background(), olderThan)
|
|
require.NoError(t, err)
|
|
require.Equal(t, 0, rowsDeleted)
|
|
})
|
|
|
|
testScenarioWithQueryInQueryHistory(t, "Not stale query history is not deleted",
|
|
func(t *testing.T, sc scenarioContext) {
|
|
olderThan := sc.service.now().Unix() - 60
|
|
rowsDeleted, err := sc.service.DeleteStaleQueriesInQueryHistory(context.Background(), olderThan)
|
|
require.NoError(t, err)
|
|
require.Equal(t, 0, rowsDeleted)
|
|
})
|
|
|
|
// In this scenario we have 2 starred queries and 1 not starred query
|
|
testScenarioWithMultipleQueriesInQueryHistory(t, "Stale starred query history can not be deleted",
|
|
func(t *testing.T, sc scenarioContext) {
|
|
olderThan := sc.service.now().Unix() + 60
|
|
rowsDeleted, err := sc.service.DeleteStaleQueriesInQueryHistory(context.Background(), olderThan)
|
|
require.NoError(t, err)
|
|
require.Equal(t, 1, rowsDeleted)
|
|
})
|
|
}
|