mirror of
https://git.numenor-labs.us/dsfx.git
synced 2025-04-29 16:20:34 +00:00
104 lines
2.3 KiB
Go
104 lines
2.3 KiB
Go
package scoped_test
|
|
|
|
import (
|
|
"io/fs"
|
|
"testing"
|
|
|
|
"koti.casa/numenor-labs/dsfx/pkg/disk"
|
|
"koti.casa/numenor-labs/dsfx/pkg/storage/scoped"
|
|
)
|
|
|
|
func TestScopedStorage_Scope(t *testing.T) {
|
|
mockDisk := &disk.MockDisk{}
|
|
storage := scoped.New(mockDisk, "testscope")
|
|
|
|
if scope := storage.Scope(); scope != "testscope" {
|
|
t.Errorf("expected 'testscope', got '%s'", scope)
|
|
}
|
|
}
|
|
|
|
func TestScopedStorage_Mkdir(t *testing.T) {
|
|
mockDisk := &disk.MockDisk{
|
|
MkdirFunc: func(name string, perm fs.FileMode) error {
|
|
if name != "testscope/testdir" {
|
|
t.Errorf("expected 'testscope/testdir', got '%s'", name)
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
storage := scoped.New(mockDisk, "testscope")
|
|
err := storage.Mkdir("testdir", 0755)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestScopedStorage_Create(t *testing.T) {
|
|
mockDisk := &disk.MockDisk{
|
|
CreateFunc: func(name string) (disk.File, error) {
|
|
if name != "testscope/testfile" {
|
|
t.Errorf("expected 'testscope/testfile', got '%s'", name)
|
|
}
|
|
return nil, nil
|
|
},
|
|
}
|
|
|
|
storage := scoped.New(mockDisk, "testscope")
|
|
_, err := storage.Create("testfile")
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestScopedStorage_Stat(t *testing.T) {
|
|
mockDisk := &disk.MockDisk{
|
|
StatFunc: func(name string) (fs.FileInfo, error) {
|
|
if name != "testscope/testfile" {
|
|
t.Errorf("expected 'testscope/testfile', got '%s'", name)
|
|
}
|
|
return nil, nil
|
|
},
|
|
}
|
|
|
|
storage := scoped.New(mockDisk, "testscope")
|
|
_, err := storage.Stat("testfile")
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestScopedStorage_Open(t *testing.T) {
|
|
mockDisk := &disk.MockDisk{
|
|
OpenFunc: func(name string) (disk.File, error) {
|
|
if name != "testscope/testfile" {
|
|
t.Errorf("expected 'testscope/testfile', got '%s'", name)
|
|
}
|
|
return nil, nil
|
|
},
|
|
}
|
|
|
|
storage := scoped.New(mockDisk, "testscope")
|
|
_, err := storage.Open("testfile")
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestScopedStorage_Remove(t *testing.T) {
|
|
mockDisk := &disk.MockDisk{
|
|
RemoveFunc: func(name string) error {
|
|
if name != "testscope/testfile" {
|
|
t.Errorf("expected 'testscope/testfile', got '%s'", name)
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
storage := scoped.New(mockDisk, "testscope")
|
|
err := storage.Remove("testfile")
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
}
|