浏览代码

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

Nicola Murino 4 年之前
父节点
当前提交
a383957cfa
共有 2 个文件被更改,包括 36 次插入2 次删除
  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)
 	rr = executeRequest(req)
 	checkResponseCode(t, http.StatusOK, rr)
-
 	var folderGet vfs.BaseVirtualFolder
 	req, _ = http.NewRequest(http.MethodGet, path.Join(folderPath, folderName), nil)
 	setBearerForReq(req, token)
@@ -4027,6 +4026,41 @@ func TestUpdateFolderQuotaUsageMock(t *testing.T) {
 	assert.NoError(t, err)
 	assert.Equal(t, usedQuotaFiles, folderGet.UsedQuotaFiles)
 	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")))
 	setBearerForReq(req, token)
 	rr = executeRequest(req)

+ 1 - 1
httpd/schema/openapi.yaml

@@ -428,7 +428,7 @@ paths:
             example: reset
       requestBody:
         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:
           application/json:
             schema: