mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-05-17 08:36:55 +03:00
Make test assertion stricter: expect exactly one part instead of at least one lib/backup/fslocal: clean directory path to handle trailing slash
30 lines
594 B
Go
30 lines
594 B
Go
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))
|
|
}
|
|
}
|