API: Fix storing dashboard with static UID (#43861)
* API: Fix storing dashboard with static UID
This commit is contained in:
@@ -97,7 +97,7 @@ func createUser(t *testing.T, store *sqlstore.SQLStore, cmd models.CreateUserCom
|
||||
return u.Id
|
||||
}
|
||||
|
||||
func TestProvisionioningDashboards(t *testing.T) {
|
||||
func TestUpdatingProvisionionedDashboards(t *testing.T) {
|
||||
// Setup Grafana and its Database
|
||||
dir, path := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||
DisableAnonymous: true,
|
||||
@@ -161,14 +161,31 @@ providers:
|
||||
testCases := []struct {
|
||||
desc string
|
||||
dashboardData string
|
||||
expStatus int
|
||||
expErrReason string
|
||||
}{
|
||||
{
|
||||
desc: "when updating provisioned dashboard using ID it should fail",
|
||||
dashboardData: fmt.Sprintf(`{"title":"just testing", "id": %d, "version": 1}`, dashboardID),
|
||||
expStatus: http.StatusBadRequest,
|
||||
expErrReason: models.ErrDashboardCannotSaveProvisionedDashboard.Reason,
|
||||
},
|
||||
{
|
||||
desc: "when updating provisioned dashboard using UID is should fail",
|
||||
desc: "when updating provisioned dashboard using UID it should fail",
|
||||
dashboardData: fmt.Sprintf(`{"title":"just testing", "uid": %q, "version": 1}`, dashboardUID),
|
||||
expStatus: http.StatusBadRequest,
|
||||
expErrReason: models.ErrDashboardCannotSaveProvisionedDashboard.Reason,
|
||||
},
|
||||
{
|
||||
desc: "when updating dashboard using unknown ID, it should fail",
|
||||
dashboardData: `{"title":"just testing", "id": 42, "version": 1}`,
|
||||
expStatus: http.StatusNotFound,
|
||||
expErrReason: models.ErrDashboardNotFound.Reason,
|
||||
},
|
||||
{
|
||||
desc: "when updating dashboard using unknown UID, it should succeed",
|
||||
dashboardData: `{"title":"just testing", "uid": "unknown", "version": 1}`,
|
||||
expStatus: http.StatusOK,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
@@ -186,17 +203,20 @@ providers:
|
||||
// nolint:gosec
|
||||
resp, err := http.Post(u, "application/json", buf)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||
assert.Equal(t, tc.expStatus, resp.StatusCode)
|
||||
t.Cleanup(func() {
|
||||
err := resp.Body.Close()
|
||||
require.NoError(t, err)
|
||||
})
|
||||
if tc.expErrReason == "" {
|
||||
return
|
||||
}
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
dashboardErr := &errorResponseBody{}
|
||||
err = json.Unmarshal(b, dashboardErr)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, models.ErrDashboardCannotSaveProvisionedDashboard.Reason, dashboardErr.Message)
|
||||
assert.Equal(t, tc.expErrReason, dashboardErr.Message)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user