mirror of
https://github.com/kopia/kopia.git
synced 2026-03-26 01:51:20 -04:00
* 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
43 lines
895 B
Go
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)
|
|
}
|