pkger/pkging/mem/embed_test.go

110 lines
3.4 KiB
Go
Raw Permalink Normal View History

2019-10-16 18:13:11 +03:00
package mem_test
2019-09-21 19:51:29 +03:00
import (
2019-10-15 23:40:45 +03:00
"bytes"
2019-09-21 19:51:29 +03:00
"os"
2019-10-15 23:40:45 +03:00
"path/filepath"
2019-09-21 19:51:29 +03:00
"testing"
"github.com/markbates/pkger/here"
2019-10-15 23:40:45 +03:00
"github.com/markbates/pkger/parser"
2019-10-16 18:13:11 +03:00
"github.com/markbates/pkger/pkging/mem"
"github.com/markbates/pkger/pkging/stuffing"
2019-09-21 19:51:29 +03:00
"github.com/stretchr/testify/require"
)
2019-10-15 23:40:45 +03:00
func Test_Pkger_Embedding(t *testing.T) {
2019-09-21 19:51:29 +03:00
r := require.New(t)
2019-10-15 23:40:45 +03:00
pwd, err := os.Getwd()
2019-09-21 19:51:29 +03:00
r.NoError(err)
2019-10-15 23:40:45 +03:00
ch := filepath.Join(pwd, "..", "..",
"examples",
"app")
2019-09-21 19:51:29 +03:00
2019-10-15 23:40:45 +03:00
info := here.Info{
Dir: ch,
ImportPath: "github.com/markbates/pkger/examples/app",
2019-09-21 19:51:29 +03:00
}
2019-10-15 23:40:45 +03:00
here.Cache(info.ImportPath, func(s string) (here.Info, error) {
return info, nil
})
2019-09-21 19:51:29 +03:00
2019-10-15 23:40:45 +03:00
paths, err := parser.Parse(info)
2019-09-21 19:51:29 +03:00
r.NoError(err)
2019-10-15 23:40:45 +03:00
ps := make([]string, len(paths))
for i, p := range paths {
ps[i] = p.String()
}
r.Equal(inbed, ps)
bb := &bytes.Buffer{}
2019-09-21 19:51:29 +03:00
2019-10-16 18:13:11 +03:00
err = stuffing.Stuff(bb, info, paths)
2019-09-21 19:51:29 +03:00
r.NoError(err)
2019-10-09 20:21:54 +03:00
2019-10-16 18:13:11 +03:00
pkg, err := mem.UnmarshalEmbed(bb.Bytes())
2019-10-15 23:40:45 +03:00
r.NoError(err)
2019-09-21 19:51:29 +03:00
2019-10-15 23:40:45 +03:00
var res []string
err = pkg.Walk("/", func(path string, info os.FileInfo, err error) error {
2019-09-21 19:51:29 +03:00
if err != nil {
return err
}
2019-10-15 23:40:45 +03:00
res = append(res, path)
2019-09-21 19:51:29 +03:00
return nil
})
2019-10-15 23:40:45 +03:00
2019-09-21 19:51:29 +03:00
r.NoError(err)
2019-10-15 23:40:45 +03:00
r.Equal(inbed, res)
}
var inbed = []string{
"github.com/gobuffalo/buffalo:/",
"github.com/gobuffalo/buffalo:/render",
"github.com/gobuffalo/buffalo:/render/auto.go",
"github.com/gobuffalo/buffalo:/render/auto_test.go",
"github.com/gobuffalo/buffalo:/render/download.go",
"github.com/gobuffalo/buffalo:/render/download_test.go",
"github.com/gobuffalo/buffalo:/render/func.go",
"github.com/gobuffalo/buffalo:/render/func_test.go",
"github.com/gobuffalo/buffalo:/render/helpers.go",
"github.com/gobuffalo/buffalo:/render/html.go",
"github.com/gobuffalo/buffalo:/render/html_test.go",
"github.com/gobuffalo/buffalo:/render/js.go",
"github.com/gobuffalo/buffalo:/render/js_test.go",
"github.com/gobuffalo/buffalo:/render/json.go",
"github.com/gobuffalo/buffalo:/render/json_test.go",
"github.com/gobuffalo/buffalo:/render/markdown_test.go",
"github.com/gobuffalo/buffalo:/render/options.go",
"github.com/gobuffalo/buffalo:/render/partials_test.go",
"github.com/gobuffalo/buffalo:/render/plain.go",
"github.com/gobuffalo/buffalo:/render/plain_test.go",
"github.com/gobuffalo/buffalo:/render/render.go",
"github.com/gobuffalo/buffalo:/render/render_test.go",
"github.com/gobuffalo/buffalo:/render/renderer.go",
"github.com/gobuffalo/buffalo:/render/sse.go",
"github.com/gobuffalo/buffalo:/render/string.go",
"github.com/gobuffalo/buffalo:/render/string_map.go",
"github.com/gobuffalo/buffalo:/render/string_map_test.go",
"github.com/gobuffalo/buffalo:/render/string_test.go",
"github.com/gobuffalo/buffalo:/render/template.go",
"github.com/gobuffalo/buffalo:/render/template_engine.go",
"github.com/gobuffalo/buffalo:/render/template_helpers.go",
"github.com/gobuffalo/buffalo:/render/template_helpers_test.go",
"github.com/gobuffalo/buffalo:/render/template_test.go",
"github.com/gobuffalo/buffalo:/render/xml.go",
"github.com/gobuffalo/buffalo:/render/xml_test.go",
"github.com/markbates/pkger/examples/app:/",
"github.com/markbates/pkger/examples/app:/public",
"github.com/markbates/pkger/examples/app:/public/images",
"github.com/markbates/pkger/examples/app:/public/images/mark-small.png",
"github.com/markbates/pkger/examples/app:/public/images/mark.png",
"github.com/markbates/pkger/examples/app:/public/images/mark_250px.png",
"github.com/markbates/pkger/examples/app:/public/images/mark_400px.png",
"github.com/markbates/pkger/examples/app:/public/index.html",
2019-09-21 19:51:29 +03:00
}