mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-31 09:20:50 +01:00
Introduce a small Loader interface so the service can stay oblivious to the storage backend behind a Parquet path: tests inject a LocalLoader backed by os.File, and the daemon will plug in a filer-backed Loader in a later milestone. FileHandle is the parser-friendly view: io.ReaderAt + io.Closer + Size(). LocalLoader rejects missing files and directories up front so service-level error paths see a clear "open failed" rather than a later ReadAt EOF. The Service does not yet consume Loader — that wiring lands in M1-C4 along with the predicate-less Pushdown handler that actually issues loads.
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package parquet_pushdown
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestLocalLoader_Open(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "a.bin")
|
|
want := []byte("hello pushdown")
|
|
if err := os.WriteFile(path, want, 0o600); err != nil {
|
|
t.Fatalf("write: %v", err)
|
|
}
|
|
|
|
h, err := LocalLoader{}.Open(context.Background(), path)
|
|
if err != nil {
|
|
t.Fatalf("open: %v", err)
|
|
}
|
|
defer h.Close()
|
|
|
|
if h.Size() != int64(len(want)) {
|
|
t.Errorf("Size = %d, want %d", h.Size(), len(want))
|
|
}
|
|
got := make([]byte, len(want))
|
|
n, err := h.ReadAt(got, 0)
|
|
if err != nil {
|
|
t.Fatalf("ReadAt: %v", err)
|
|
}
|
|
if n != len(want) || string(got) != string(want) {
|
|
t.Errorf("got %q (n=%d), want %q", got[:n], n, want)
|
|
}
|
|
}
|
|
|
|
func TestLocalLoader_RejectsMissing(t *testing.T) {
|
|
if _, err := (LocalLoader{}).Open(context.Background(), filepath.Join(t.TempDir(), "missing.bin")); err == nil {
|
|
t.Error("expected error opening missing file")
|
|
}
|
|
}
|
|
|
|
func TestLocalLoader_RejectsDirectory(t *testing.T) {
|
|
dir := t.TempDir()
|
|
if _, err := (LocalLoader{}).Open(context.Background(), dir); err == nil {
|
|
t.Error("expected error opening a directory")
|
|
}
|
|
}
|