Enchantrix/rootfs/local_test.go
google-labs-jules[bot] 4b7d76e993 feat: Implement rootfs passthrough storage
This commit introduces a new `rootfs` package that provides an encrypted passthrough storage system. The `LocalStorage` implementation uses the local file system as its backing store and encrypts all data at rest using the `chachapoly` package.

The functionality is exposed through the main `crypt` package, providing a clean and simple API for creating and interacting with encrypted file-based storage.
2025-10-30 23:55:25 +00:00

42 lines
951 B
Go

package rootfs
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLocalStorage(t *testing.T) {
// Create a temporary directory for testing.
tempDir, err := os.MkdirTemp("", "enchantrix-test")
assert.NoError(t, err)
defer os.RemoveAll(tempDir)
// Create a new LocalStorage instance.
key := make([]byte, 32)
for i := range key {
key[i] = 1
}
storage := NewLocalStorage(tempDir, key)
// Test Write and Read.
err = storage.Write("test.txt", []byte("hello"))
assert.NoError(t, err)
data, err := storage.Read("test.txt")
assert.NoError(t, err)
assert.Equal(t, []byte("hello"), data)
// Test List.
files, err := storage.List("")
assert.NoError(t, err)
assert.Len(t, files, 1)
assert.Equal(t, "test.txt", files[0].Name())
// Test Delete.
err = storage.Delete("test.txt")
assert.NoError(t, err)
_, err = os.Stat(filepath.Join(tempDir, "test.txt"))
assert.True(t, os.IsNotExist(err))
}