mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
use dynamic ID in test assertion for search (#33320)
This commit is contained in:
parent
d2d13ea39a
commit
e642506dcb
@ -33,7 +33,8 @@ func TestBuilder_EqualResults_Basic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
db := setupTestEnvironment(t)
|
db := setupTestEnvironment(t)
|
||||||
createDashboards(t, db, 0, 1, user.OrgId)
|
dashIds := createDashboards(t, db, 0, 1, user.OrgId)
|
||||||
|
require.Len(t, dashIds, 1)
|
||||||
|
|
||||||
// create one dashboard in another organization that shouldn't
|
// create one dashboard in another organization that shouldn't
|
||||||
// be listed in the results.
|
// be listed in the results.
|
||||||
@ -58,7 +59,7 @@ func TestBuilder_EqualResults_Basic(t *testing.T) {
|
|||||||
res[0].UID = ""
|
res[0].UID = ""
|
||||||
assert.EqualValues(t, []sqlstore.DashboardSearchProjection{
|
assert.EqualValues(t, []sqlstore.DashboardSearchProjection{
|
||||||
{
|
{
|
||||||
ID: 1,
|
ID: dashIds[0],
|
||||||
Title: "A",
|
Title: "A",
|
||||||
Slug: "a",
|
Slug: "a",
|
||||||
Term: "templated",
|
Term: "templated",
|
||||||
@ -156,11 +157,12 @@ func setupTestEnvironment(t *testing.T) *sqlstore.SQLStore {
|
|||||||
return store
|
return store
|
||||||
}
|
}
|
||||||
|
|
||||||
func createDashboards(t *testing.T, db *sqlstore.SQLStore, startID, endID int, orgID int64) {
|
func createDashboards(t *testing.T, db *sqlstore.SQLStore, startID, endID int, orgID int64) []int64 {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
require.GreaterOrEqual(t, endID, startID)
|
require.GreaterOrEqual(t, endID, startID)
|
||||||
|
|
||||||
|
createdIds := []int64{}
|
||||||
for i := startID; i < endID; i++ {
|
for i := startID; i < endID; i++ {
|
||||||
dashboard, err := simplejson.NewJson([]byte(`{
|
dashboard, err := simplejson.NewJson([]byte(`{
|
||||||
"id": null,
|
"id": null,
|
||||||
@ -172,14 +174,18 @@ func createDashboards(t *testing.T, db *sqlstore.SQLStore, startID, endID int, o
|
|||||||
"version": 0
|
"version": 0
|
||||||
}`))
|
}`))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = db.SaveDashboard(models.SaveDashboardCommand{
|
dash, err := db.SaveDashboard(models.SaveDashboardCommand{
|
||||||
Dashboard: dashboard,
|
Dashboard: dashboard,
|
||||||
UserId: 1,
|
UserId: 1,
|
||||||
OrgId: orgID,
|
OrgId: orgID,
|
||||||
UpdatedAt: time.Now(),
|
UpdatedAt: time.Now(),
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
createdIds = append(createdIds, dash.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return createdIds
|
||||||
}
|
}
|
||||||
|
|
||||||
// lexiCounter counts in a lexicographically sortable order.
|
// lexiCounter counts in a lexicographically sortable order.
|
||||||
|
Loading…
Reference in New Issue
Block a user