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:
ugurtafrali
2026-04-16 04:48:39 +03:00
committed by Jayice
parent cc3a14b16b
commit fe1a2503b4
2 changed files with 30 additions and 0 deletions

View File

@@ -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)
}

View 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))
}
}