mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
API: add ID to snapshot API responses (#29600)
* API: add ID to snapshot API responses * API: update snapshot tests
This commit is contained in:
parent
bb45f5fedc
commit
d92beeee3d
@ -68,7 +68,8 @@ JSON Body schema:
|
||||
"deleteKey":"XXXXXXX",
|
||||
"deleteUrl":"myurl/api/snapshots-delete/XXXXXXX",
|
||||
"key":"YYYYYYY",
|
||||
"url":"myurl/dashboard/snapshot/YYYYYYY"
|
||||
"url":"myurl/dashboard/snapshot/YYYYYYY",
|
||||
"id": 1,
|
||||
}
|
||||
```
|
||||
|
||||
@ -192,7 +193,7 @@ Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||||
HTTP/1.1 200
|
||||
Content-Type: application/json
|
||||
|
||||
{"message":"Snapshot deleted. It might take an hour before it's cleared from any CDN caches."}
|
||||
{"message":"Snapshot deleted. It might take an hour before it's cleared from any CDN caches.", "id": 1}
|
||||
```
|
||||
|
||||
## Delete Snapshot by deleteKey
|
||||
@ -214,5 +215,5 @@ Accept: application/json
|
||||
HTTP/1.1 200
|
||||
Content-Type: application/json
|
||||
|
||||
{"message":"Snapshot deleted. It might take an hour before it's cleared from any CDN caches."}
|
||||
{"message":"Snapshot deleted. It might take an hour before it's cleared from any CDN caches.", "id": 1}
|
||||
```
|
@ -132,6 +132,7 @@ func CreateDashboardSnapshot(c *models.ReqContext, cmd models.CreateDashboardSna
|
||||
"deleteKey": cmd.DeleteKey,
|
||||
"url": url,
|
||||
"deleteUrl": setting.ToAbsUrl("api/snapshots-delete/" + cmd.DeleteKey),
|
||||
"id": cmd.Result.Id,
|
||||
})
|
||||
}
|
||||
|
||||
@ -223,7 +224,10 @@ func DeleteDashboardSnapshotByDeleteKey(c *models.ReqContext) Response {
|
||||
return Error(500, "Failed to delete dashboard snapshot", err)
|
||||
}
|
||||
|
||||
return JSON(200, util.DynMap{"message": "Snapshot deleted. It might take an hour before it's cleared from any CDN caches."})
|
||||
return JSON(200, util.DynMap{
|
||||
"message": "Snapshot deleted. It might take an hour before it's cleared from any CDN caches.",
|
||||
"id": query.Result.Id,
|
||||
})
|
||||
}
|
||||
|
||||
// DELETE /api/snapshots/:key
|
||||
@ -269,7 +273,10 @@ func DeleteDashboardSnapshot(c *models.ReqContext) Response {
|
||||
return Error(500, "Failed to delete dashboard snapshot", err)
|
||||
}
|
||||
|
||||
return JSON(200, util.DynMap{"message": "Snapshot deleted. It might take an hour before it's cleared from any CDN caches."})
|
||||
return JSON(200, util.DynMap{
|
||||
"message": "Snapshot deleted. It might take an hour before it's cleared from any CDN caches.",
|
||||
"id": query.Result.Id,
|
||||
})
|
||||
}
|
||||
|
||||
// GET /api/dashboard/snapshots
|
||||
|
@ -109,6 +109,7 @@ func TestDashboardSnapshotAPIEndpoint_singleSnapshot(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, strings.HasPrefix(respJSON.Get("message").MustString(), "Snapshot deleted"))
|
||||
assert.Equal(t, 1, respJSON.Get("id").MustInt())
|
||||
|
||||
assert.Equal(t, http.MethodGet, externalRequest.Method)
|
||||
assert.Equal(t, ts.URL, fmt.Sprintf("http://%s", externalRequest.Host))
|
||||
@ -141,6 +142,7 @@ func TestDashboardSnapshotAPIEndpoint_singleSnapshot(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, strings.HasPrefix(respJSON.Get("message").MustString(), "Snapshot deleted"))
|
||||
assert.Equal(t, 1, respJSON.Get("id").MustInt())
|
||||
assert.Equal(t, ts.URL, fmt.Sprintf("http://%s", externalRequest.Host))
|
||||
assert.Equal(t, "/", externalRequest.URL.EscapedPath())
|
||||
})
|
||||
@ -163,6 +165,7 @@ func TestDashboardSnapshotAPIEndpoint_singleSnapshot(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, strings.HasPrefix(respJSON.Get("message").MustString(), "Snapshot deleted"))
|
||||
assert.Equal(t, 1, respJSON.Get("id").MustInt())
|
||||
})
|
||||
})
|
||||
|
||||
@ -186,6 +189,11 @@ func TestDashboardSnapshotAPIEndpoint_singleSnapshot(t *testing.T) {
|
||||
|
||||
require.NoError(t, writeErr)
|
||||
assert.Equal(t, 200, sc.resp.Code)
|
||||
respJSON, err := simplejson.NewJson(sc.resp.Body.Bytes())
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, strings.HasPrefix(respJSON.Get("message").MustString(), "Snapshot deleted"))
|
||||
assert.Equal(t, 1, respJSON.Get("id").MustInt())
|
||||
})
|
||||
|
||||
loggedInUserScenarioWithRole(t,
|
||||
|
Loading…
Reference in New Issue
Block a user