pkger/fs/fstest/fstest.go

45 lines
691 B
Go
Raw Normal View History

2019-09-01 05:45:22 +03:00
package fstest
import (
"path"
"strings"
"github.com/markbates/pkger/fs"
)
func Files(fx fs.FileSystem) (TestFiles, error) {
tf := TestFiles{}
for _, f := range fileList {
2019-09-01 06:29:25 +03:00
pt, err := Path(fx, f)
if err != nil {
return tf, err
}
tf[pt] = TestFile{
Name: pt.Name,
Path: pt,
2019-09-01 05:45:22 +03:00
}
}
return tf, nil
}
2019-09-01 06:29:25 +03:00
func Path(fx fs.FileSystem, ps ...string) (fs.Path, error) {
name := path.Join(ps...)
name = path.Join(".fstest", name)
if !strings.HasPrefix(name, "/") {
name = "/" + name
}
return fx.Parse(name)
2019-09-01 05:45:22 +03:00
}
var fileList = []string{
"/main.go",
"/go.mod",
"/go.sum",
"/public/index.html",
"/public/images/mark.png",
"/templates/a.txt",
"/templates/b/b.txt",
}