Sfoglia il codice sorgente

OpenAPI: document that also folder-quota-update supports partial updates

Nicola Murino 4 anni fa
parent
commit
a383957cfa
2 ha cambiato i file con 36 aggiunte e 2 eliminazioni
  1. 35 1
      httpd/httpd_test.go
  2. 1 1
      httpd/schema/openapi.yaml

+ 35 - 1
httpd/httpd_test.go

@@ -4017,7 +4017,6 @@ func TestUpdateFolderQuotaUsageMock(t *testing.T) {
 	setBearerForReq(req, token)
 	setBearerForReq(req, token)
 	rr = executeRequest(req)
 	rr = executeRequest(req)
 	checkResponseCode(t, http.StatusOK, rr)
 	checkResponseCode(t, http.StatusOK, rr)
-
 	var folderGet vfs.BaseVirtualFolder
 	var folderGet vfs.BaseVirtualFolder
 	req, _ = http.NewRequest(http.MethodGet, path.Join(folderPath, folderName), nil)
 	req, _ = http.NewRequest(http.MethodGet, path.Join(folderPath, folderName), nil)
 	setBearerForReq(req, token)
 	setBearerForReq(req, token)
@@ -4027,6 +4026,41 @@ func TestUpdateFolderQuotaUsageMock(t *testing.T) {
 	assert.NoError(t, err)
 	assert.NoError(t, err)
 	assert.Equal(t, usedQuotaFiles, folderGet.UsedQuotaFiles)
 	assert.Equal(t, usedQuotaFiles, folderGet.UsedQuotaFiles)
 	assert.Equal(t, usedQuotaSize, folderGet.UsedQuotaSize)
 	assert.Equal(t, usedQuotaSize, folderGet.UsedQuotaSize)
+	// now update only quota size
+	f.UsedQuotaFiles = 0
+	folderAsJSON, err = json.Marshal(f)
+	assert.NoError(t, err)
+	req, _ = http.NewRequest(http.MethodPut, updateFolderUsedQuotaPath+"?mode=add", bytes.NewBuffer(folderAsJSON))
+	setBearerForReq(req, token)
+	rr = executeRequest(req)
+	checkResponseCode(t, http.StatusOK, rr)
+	folderGet = vfs.BaseVirtualFolder{}
+	req, _ = http.NewRequest(http.MethodGet, path.Join(folderPath, folderName), nil)
+	setBearerForReq(req, token)
+	rr = executeRequest(req)
+	checkResponseCode(t, http.StatusOK, rr)
+	err = render.DecodeJSON(rr.Body, &folderGet)
+	assert.NoError(t, err)
+	assert.Equal(t, usedQuotaFiles, folderGet.UsedQuotaFiles)
+	assert.Equal(t, usedQuotaSize*2, folderGet.UsedQuotaSize)
+	// now update only quota files
+	f.UsedQuotaSize = 0
+	f.UsedQuotaFiles = 1
+	folderAsJSON, err = json.Marshal(f)
+	assert.NoError(t, err)
+	req, _ = http.NewRequest(http.MethodPut, updateFolderUsedQuotaPath+"?mode=add", bytes.NewBuffer(folderAsJSON))
+	setBearerForReq(req, token)
+	rr = executeRequest(req)
+	checkResponseCode(t, http.StatusOK, rr)
+	folderGet = vfs.BaseVirtualFolder{}
+	req, _ = http.NewRequest(http.MethodGet, path.Join(folderPath, folderName), nil)
+	setBearerForReq(req, token)
+	rr = executeRequest(req)
+	checkResponseCode(t, http.StatusOK, rr)
+	err = render.DecodeJSON(rr.Body, &folderGet)
+	assert.NoError(t, err)
+	assert.Equal(t, usedQuotaFiles*2, folderGet.UsedQuotaFiles)
+	assert.Equal(t, usedQuotaSize*2, folderGet.UsedQuotaSize)
 	req, _ = http.NewRequest(http.MethodPut, updateFolderUsedQuotaPath, bytes.NewBuffer([]byte("string")))
 	req, _ = http.NewRequest(http.MethodPut, updateFolderUsedQuotaPath, bytes.NewBuffer([]byte("string")))
 	setBearerForReq(req, token)
 	setBearerForReq(req, token)
 	rr = executeRequest(req)
 	rr = executeRequest(req)

+ 1 - 1
httpd/schema/openapi.yaml

@@ -428,7 +428,7 @@ paths:
             example: reset
             example: reset
       requestBody:
       requestBody:
         required: true
         required: true
-        description: 'The only folder mandatory fields are mapped_path,used_quota_size and used_quota_files. Please note that if the used quota fields are missing they will default to 0'
+        description: 'The only folder mandatory fields are mapped_path,used_quota_size and used_quota_files. Please note that if the used quota fields are missing they will default to 0, this means that if mode is "add" the current value will remain unchanged, if mode is "reset" the missing field is set to 0'
         content:
         content:
           application/json:
           application/json:
             schema:
             schema: