mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 16:49:41 +00:00
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func writeFileWithSize(t *testing.T, path string, size int) {
|
|
t.Helper()
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
|
t.Fatalf("mkdir %s: %v", path, err)
|
|
}
|
|
content := make([]byte, size)
|
|
if err := os.WriteFile(path, content, 0o644); err != nil {
|
|
t.Fatalf("write %s: %v", path, err)
|
|
}
|
|
}
|
|
|
|
func TestGetDirectoryLogicalSizeWithExclude(t *testing.T) {
|
|
base := t.TempDir()
|
|
homeFile := filepath.Join(base, "fileA")
|
|
libFile := filepath.Join(base, "Library", "fileB")
|
|
projectLibFile := filepath.Join(base, "Projects", "Library", "fileC")
|
|
|
|
writeFileWithSize(t, homeFile, 100)
|
|
writeFileWithSize(t, libFile, 200)
|
|
writeFileWithSize(t, projectLibFile, 300)
|
|
|
|
total, err := getDirectoryLogicalSizeWithExclude(base, "")
|
|
if err != nil {
|
|
t.Fatalf("getDirectoryLogicalSizeWithExclude (no exclude) error: %v", err)
|
|
}
|
|
if total != 600 {
|
|
t.Fatalf("expected total 600 bytes, got %d", total)
|
|
}
|
|
|
|
excluding, err := getDirectoryLogicalSizeWithExclude(base, filepath.Join(base, "Library"))
|
|
if err != nil {
|
|
t.Fatalf("getDirectoryLogicalSizeWithExclude (exclude Library) error: %v", err)
|
|
}
|
|
if excluding != 400 {
|
|
t.Fatalf("expected 400 bytes when excluding top-level Library, got %d", excluding)
|
|
}
|
|
}
|