From 488ccdebe437ea8357a7c090dd94f991d40e7d3c Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 18 Apr 2024 22:19:55 -0700 Subject: [PATCH] Cleanup --- plugins/sideload/sideload.go | 26 +++++++++++++------ plugins/sideload/sideload_test.go | 8 +++++- plugins/sideload/testdata/reference/1.txt | 0 .../sideload/testdata/reference/child/2.txt | 0 4 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 plugins/sideload/testdata/reference/1.txt create mode 100644 plugins/sideload/testdata/reference/child/2.txt diff --git a/plugins/sideload/sideload.go b/plugins/sideload/sideload.go index 97c76f9..858af9a 100644 --- a/plugins/sideload/sideload.go +++ b/plugins/sideload/sideload.go @@ -2,16 +2,23 @@ package sideload import ( "bytes" - "embed" + "io/fs" "path/filepath" "git.foosoft.net/alex/goldsmith" ) -type Sideload struct { - files []*goldsmith.File - fileSystems []embed.FS -} +type ( + Sideload struct { + files []*goldsmith.File + fileSystems []sideloadFs + } + + sideloadFs interface { + fs.ReadDirFS + fs.ReadFileFS + } +) func New() *Sideload { return &Sideload{} @@ -45,12 +52,15 @@ func (self *Sideload) Files(files ...*goldsmith.File) *Sideload { return self } -func (self *Sideload) FileSystems(fileSystems ...embed.FS) *Sideload { - self.fileSystems = append(self.fileSystems, fileSystems...) +func (self *Sideload) FileSystems(fileSystems ...fs.FS) *Sideload { + for _, fileSystem := range fileSystems { + self.fileSystems = append(self.fileSystems, fileSystem.(sideloadFs)) + } + return self } -func (self *Sideload) gatherFsFiles(context *goldsmith.Context, fileSystem embed.FS, path string) ([]*goldsmith.File, error) { +func (self *Sideload) gatherFsFiles(context *goldsmith.Context, fileSystem sideloadFs, path string) ([]*goldsmith.File, error) { entries, err := fileSystem.ReadDir(path) if err != nil { return nil, err diff --git a/plugins/sideload/sideload_test.go b/plugins/sideload/sideload_test.go index bbc0fa8..eac1685 100644 --- a/plugins/sideload/sideload_test.go +++ b/plugins/sideload/sideload_test.go @@ -1,6 +1,7 @@ package sideload import ( + "io/fs" "testing" "embed" @@ -13,10 +14,15 @@ import ( var embedFs embed.FS func Test(self *testing.T) { + subFs, err := fs.Sub(embedFs, "testdata/source") + if err != nil { + panic(err) + } + harness.Validate( self, func(gs *goldsmith.Goldsmith) { - gs.Chain(New().FileSystems(embedFs)) + gs.Chain(New().FileSystems(subFs)) }, ) } diff --git a/plugins/sideload/testdata/reference/1.txt b/plugins/sideload/testdata/reference/1.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugins/sideload/testdata/reference/child/2.txt b/plugins/sideload/testdata/reference/child/2.txt new file mode 100644 index 0000000..e69de29