mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-05-17 00:26:36 +03:00
lib/backup/fslocal: clean directory path to handle trailing slash
Make test assertion stricter: expect exactly one part instead of at least one lib/backup/fslocal: clean directory path to handle trailing slash
This commit is contained in:
@@ -33,6 +33,7 @@ type FS struct {
|
||||
//
|
||||
// The returned fs must be stopped when no long needed with MustStop call.
|
||||
func (fs *FS) Init() error {
|
||||
fs.Dir = filepath.Clean(fs.Dir)
|
||||
if fs.MaxBytesPerSecond > 0 {
|
||||
fs.bl = newBandwidthLimiter(fs.MaxBytesPerSecond)
|
||||
}
|
||||
|
||||
29
lib/backup/fslocal/fslocal_test.go
Normal file
29
lib/backup/fslocal/fslocal_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package fslocal
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFSInitCleanDir(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(dir, "testfile"), []byte("x"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// trailing slash must not cause ListParts to panic
|
||||
fs := &FS{Dir: dir + string(filepath.Separator)}
|
||||
if err := fs.Init(); err != nil {
|
||||
t.Fatalf("Init error: %s", err)
|
||||
}
|
||||
defer fs.MustStop()
|
||||
|
||||
parts, err := fs.ListParts()
|
||||
if err != nil {
|
||||
t.Fatalf("ListParts error: %s", err)
|
||||
}
|
||||
if len(parts) != 1 {
|
||||
t.Fatalf("expected 1 part, got %d", len(parts))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user