pkger/pkging/pkgutil/stuff_test.go

62 lines
1.1 KiB
Go
Raw Permalink Normal View History

2019-11-01 22:53:54 +03:00
package pkgutil
import (
"bytes"
"os"
"testing"
"github.com/markbates/pkger/parser"
"github.com/markbates/pkger/pkging/mem"
2019-11-01 23:08:10 +03:00
"github.com/markbates/pkger/pkging/pkgtest"
2019-11-01 22:53:54 +03:00
"github.com/markbates/pkger/pkging/stdos"
"github.com/stretchr/testify/require"
)
func Test_Stuff(t *testing.T) {
r := require.New(t)
2019-11-01 23:08:10 +03:00
ref, err := pkgtest.NewRef()
2019-11-01 22:53:54 +03:00
r.NoError(err)
defer os.RemoveAll(ref.Dir)
disk, err := stdos.New(ref.Info)
r.NoError(err)
2019-11-01 23:08:10 +03:00
infos, err := pkgtest.LoadFiles("/", ref, disk)
2019-11-01 22:53:54 +03:00
r.NoError(err)
r.Len(infos, 34)
decls, err := parser.Parse(ref.Info)
r.NoError(err)
r.Len(decls, 9)
files, err := decls.Files()
r.NoError(err)
for _, f := range files {
r.Equal("app", f.Path.Pkg)
}
r.Len(files, 22)
bb := &bytes.Buffer{}
err = Stuff(bb, ref.Info, decls)
r.NoError(err)
pkg, err := mem.UnmarshalEmbed(bb.Bytes())
r.NoError(err)
2019-11-01 23:08:10 +03:00
pkgtest.CurrentTest(t, ref, pkg)
pkgtest.InfoTest(t, ref, pkg)
pkgtest.OpenTest(t, ref, pkg)
pkgtest.WalkTest(t, ref, pkg)
2019-11-01 22:53:54 +03:00
_, err = pkg.Stat("/go.mod")
r.NoError(err)
_, err = pkg.Stat("/public/index.html")
r.NoError(err)
}