Files
kopia/internal/stat/stat_test.go
Julio Lopez 735adfcf85 refactor(general): small misc. cleanups (#4666)
* remove unnecessary type argument
* modernize with max
* unexport getPartial and update comment
* unexport getFull
* verifyNotCached helper
* use require helpers
* leverage verify[Not]Cached
* use windowsOSName const
* fix comment wrapping
* require in stat_test
* use 512 as the write size and log allocated size
* rename const to expectedMinAllocSize
* write a single byte to test file
* add TestGetBlockSizeFromCurrentFS
* require Positive
* log before invariant check
2025-06-13 23:56:37 -07:00

43 lines
895 B
Go

//go:build !windows
// +build !windows
package stat
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func TestGetBlockSize(t *testing.T) {
size, err := GetBlockSize(os.DevNull)
require.NoError(t, err)
require.Positive(t, size)
}
func TestGetBlockSizeFromCurrentFS(t *testing.T) {
size, err := GetBlockSize(".")
require.NoError(t, err)
require.Positive(t, size)
}
func TestGetFileAllocSize(t *testing.T) {
const expectedMinAllocSize = 512
d := t.TempDir()
f := filepath.Join(d, "test")
err := os.WriteFile(f, []byte{1}, os.ModePerm)
require.NoError(t, err)
s, err := GetFileAllocSize(f)
require.NoError(t, err, "error getting file alloc size for %s: %v", f, err)
t.Log("file alloc size:", s)
require.GreaterOrEqual(t, s, uint64(expectedMinAllocSize), "invalid allocated file size %d, expected at least %d", s, expectedMinAllocSize)
}