Chore: Fix http: superfluous response.WriteHeader error when deleting an external snapshot (#36780)

This commit is contained in:
Marcus Efraimsson 2021-07-15 15:29:52 +02:00 committed by GitHub
parent fdad8558ee
commit b164c90e91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -185,9 +185,12 @@ func deleteExternalDashboardSnapshot(externalUrl string) error {
if err != nil { if err != nil {
return err return err
} }
defer func() {
if err := response.Body.Close(); err != nil { if err := response.Body.Close(); err != nil {
plog.Warn("Failed closing response body", "err", err) plog.Warn("Failed to close response body", "err", err)
} }
}()
if response.StatusCode == 200 { if response.StatusCode == 200 {
return nil return nil

View File

@ -171,16 +171,16 @@ func TestDashboardSnapshotAPIEndpoint_singleSnapshot(t *testing.T) {
t.Run("When deleting an external snapshot", func(t *testing.T) { t.Run("When deleting an external snapshot", func(t *testing.T) {
aclMockResp = []*models.DashboardAclInfoDTO{} aclMockResp = []*models.DashboardAclInfoDTO{}
var writeErr error
loggedInUserScenarioWithRole(t, loggedInUserScenarioWithRole(t,
"Should gracefully delete local snapshot when remote snapshot has already been removed when calling DELETE on", "Should gracefully delete local snapshot when remote snapshot has already been removed when calling DELETE on",
"DELETE", "/api/snapshots/12345", "/api/snapshots/:key", models.ROLE_EDITOR, func(sc *scenarioContext) { "DELETE", "/api/snapshots/12345", "/api/snapshots/:key", models.ROLE_EDITOR, func(sc *scenarioContext) {
mockSnapshotResult := setUpSnapshotTest(t) mockSnapshotResult := setUpSnapshotTest(t)
mockSnapshotResult.UserId = testUserID mockSnapshotResult.UserId = testUserID
var writeErr error
ts := setupRemoteServer(func(rw http.ResponseWriter, req *http.Request) { ts := setupRemoteServer(func(rw http.ResponseWriter, req *http.Request) {
_, writeErr = rw.Write([]byte(`{"message":"Failed to get dashboard snapshot"}`))
rw.WriteHeader(500) rw.WriteHeader(500)
_, writeErr = rw.Write([]byte(`{"message":"Failed to get dashboard snapshot"}`))
}) })
mockSnapshotResult.ExternalDeleteUrl = ts.URL mockSnapshotResult.ExternalDeleteUrl = ts.URL