Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/cloud/provider_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (p localFolder) list() ([]CloudFile, error) {
}
entries, err := os.ReadDir(p.cfg.URL)
if err != nil {
return []CloudFile{}, nil
return nil, fmt.Errorf("read local folder destination %q: %w", p.cfg.URL, err)
}
var files []CloudFile
for _, e := range entries {
Expand Down
45 changes: 45 additions & 0 deletions internal/cloud/provider_local_integrity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cloud

import (
"os"
"path/filepath"
"testing"

"github.com/opensave/opensave/internal/store"
)

func TestLocalFolderListPropagatesDirectoryErrors(t *testing.T) {
t.Run("absent directory", func(t *testing.T) {
missing := filepath.Join(t.TempDir(), "missing-share")
files, err := (localFolder{cfg: store.CloudConfig{URL: missing}}).list()
if err == nil {
t.Fatalf("list = %+v, nil error; want missing-directory error", files)
}
})

t.Run("configured path is not a directory", func(t *testing.T) {
path := filepath.Join(t.TempDir(), "not-a-directory")
if err := os.WriteFile(path, []byte("x"), 0o600); err != nil {
t.Fatal(err)
}
files, err := (localFolder{cfg: store.CloudConfig{URL: path}}).list()
if err == nil {
t.Fatalf("list = %+v, nil error; want directory-read error", files)
}
})
}

func TestLocalFolderListStillSupportsOrdinaryFolders(t *testing.T) {
dir := t.TempDir()
want := []byte("synthetic zip")
if err := os.WriteFile(filepath.Join(dir, "game__main__snap_1.zip"), want, 0o600); err != nil {
t.Fatal(err)
}
files, err := (localFolder{cfg: store.CloudConfig{URL: dir}}).list()
if err != nil {
t.Fatalf("list: %v", err)
}
if len(files) != 1 || files[0].Name != "game__main__snap_1.zip" || files[0].SizeBytes != int64(len(want)) {
t.Fatalf("list = %+v", files)
}
}
Loading