feat(files): enable space limit

This commit is contained in:
hexxa 2021-08-16 22:18:07 +08:00 committed by Hexxa
parent 921a7c1ef9
commit 41654e36d0
5 changed files with 181 additions and 64 deletions

View file

@ -82,7 +82,11 @@ func TestConcurrency(t *testing.T) {
users[userName] = adResp.ID
}
filesSize := 10
getFilePath := func(name string, i int) string {
return fmt.Sprintf("%s/files/home_file_%d", name, i)
}
filesCount := 10
mockClient := func(name, pwd string, wg *sync.WaitGroup) {
usersCl := client.NewSingleUserClient(addr)
resp, _, errs := usersCl.Login(name, pwd)
@ -95,8 +99,8 @@ func TestConcurrency(t *testing.T) {
files := map[string]string{}
content := "12345678"
for i := range make([]int, filesSize, filesSize) {
files[fmt.Sprintf("%s/files/home_file_%d", name, i)] = content
for i := range make([]int, filesCount, filesCount) {
files[getFilePath(name, i)] = content
}
for filePath, content := range files {
@ -118,6 +122,34 @@ func TestConcurrency(t *testing.T) {
t.Fatalf("incorrct metadata size (%d)", len(lsResp.Metadatas))
}
resp, selfResp, errs := usersCl.Self(token)
if len(errs) > 0 {
t.Fatal(errs)
} else if resp.StatusCode != 200 {
t.Fatal("failed to self")
}
if selfResp.UsedSpace != int64(filesCount*len(content)) {
t.Fatalf("usedSpace(%d) doesn't match (%d)", selfResp.UsedSpace, filesCount*len(content))
}
resp, _, errs = filesCl.Delete(getFilePath(name, 0))
if len(errs) > 0 {
t.Fatal(errs)
} else if resp.StatusCode != 200 {
t.Fatal("failed to add user")
}
resp, selfResp, errs = usersCl.Self(token)
if len(errs) > 0 {
t.Fatal(errs)
} else if resp.StatusCode != 200 {
t.Fatal("failed to self")
}
if selfResp.UsedSpace != int64((filesCount-1)*len(content)) {
t.Fatalf("usedSpace(%d) doesn't match (%d)", selfResp.UsedSpace, int64((filesCount-1)*len(content)))
}
fmt.Println("\n\n\n", selfResp.UsedSpace, int64((filesCount-1)*len(content)))
wg.Done()
}