Dashboards: Add Dashboard API Validation tests and fix underlying issues (#103502)

This commit is contained in:
Marco de Abreu
2025-04-07 05:44:28 +03:00
committed by GitHub
parent 427715b070
commit b2f80d4dca
16 changed files with 1521 additions and 240 deletions
@@ -36,7 +36,6 @@ import (
"github.com/grafana/grafana/pkg/tests/testinfra"
"github.com/grafana/grafana/pkg/tests/testsuite"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/util/retryer"
)
func TestMain(m *testing.M) {
@@ -210,34 +209,23 @@ providers:
title := "Grafana Dev Overview & Home"
dashboardList := &model.HitList{}
retry := 0
retries := 5
// retry until the provisioned dashboard is ready
err := retryer.Retry(func() (retryer.RetrySignal, error) {
retry++
require.EventuallyWithT(t, func(collect *assert.CollectT) {
u := fmt.Sprintf("http://admin:admin@%s/api/search?query=%s", grafanaListedAddr, url.QueryEscape(title))
// nolint:gosec
resp, err := http.Get(u)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
t.Cleanup(func() {
err := resp.Body.Close()
require.NoError(t, err)
})
b, err := io.ReadAll(resp.Body)
require.NoError(t, err)
err = resp.Body.Close()
require.NoError(t, err)
err = json.Unmarshal(b, dashboardList)
require.NoError(t, err)
if dashboardList.Len() == 0 {
if retry >= retries {
return retryer.FuncError, fmt.Errorf("max retries exceeded")
}
t.Log("Dashboard is not ready", "retry", retry)
return retryer.FuncFailure, nil
}
return retryer.FuncComplete, nil
}, retries, time.Millisecond*time.Duration(25), time.Second)
require.NoError(t, err)
assert.Greater(collect, dashboardList.Len(), 0, "Dashboard should be ready")
}, 10*time.Second, 25*time.Millisecond)
var dashboardUID string
var dashboardID int64