mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 06:40:54 +03:00
webdav test: add some more logs
QuotaLimits test case sometime fails when running in CI, try to understand the reason
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package webdavd_test
|
package webdavd_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
@@ -1151,7 +1152,9 @@ func TestQuotaLimits(t *testing.T) {
|
|||||||
client := getWebDavClient(user, true, nil)
|
client := getWebDavClient(user, true, nil)
|
||||||
// test quota files
|
// test quota files
|
||||||
err = uploadFile(testFilePath, testFileName+".quota", testFileSize, client)
|
err = uploadFile(testFilePath, testFileName+".quota", testFileSize, client)
|
||||||
assert.NoError(t, err, "username: %v", user.Username)
|
if !assert.NoError(t, err, "username: %v", user.Username) {
|
||||||
|
printLatestLogs(10)
|
||||||
|
}
|
||||||
err = uploadFile(testFilePath, testFileName+".quota1", testFileSize, client)
|
err = uploadFile(testFilePath, testFileName+".quota1", testFileSize, client)
|
||||||
assert.Error(t, err, "username: %v", user.Username)
|
assert.Error(t, err, "username: %v", user.Username)
|
||||||
err = client.Rename(testFileName+".quota", testFileName, false)
|
err = client.Rename(testFileName+".quota", testFileName, false)
|
||||||
@@ -2370,11 +2373,11 @@ func uploadFile(localSourcePath string, remoteDestPath string, expectedSize int6
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if expectedSize > 0 {
|
if expectedSize > 0 {
|
||||||
err = checkFileSize(remoteDestPath, expectedSize, client)
|
return checkFileSize(remoteDestPath, expectedSize, client)
|
||||||
if err != nil {
|
/*if err != nil {
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
return checkFileSize(remoteDestPath, expectedSize, client)
|
return checkFileSize(remoteDestPath, expectedSize, client)
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -2542,3 +2545,26 @@ func createTestFile(path string, size int64) error {
|
|||||||
}
|
}
|
||||||
return os.WriteFile(path, content, os.ModePerm)
|
return os.WriteFile(path, content, os.ModePerm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printLatestLogs(maxNumberOfLines int) {
|
||||||
|
var lines []string
|
||||||
|
f, err := os.Open(logFilePath)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
scanner := bufio.NewScanner(f)
|
||||||
|
for scanner.Scan() {
|
||||||
|
lines = append(lines, scanner.Text()+"\r\n")
|
||||||
|
for len(lines) > maxNumberOfLines {
|
||||||
|
lines = lines[1:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if scanner.Err() != nil {
|
||||||
|
logger.WarnToConsole("Unable to print latest logs: %v", scanner.Err())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, line := range lines {
|
||||||
|
logger.DebugToConsole(line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user