pkger/pkging/pkgutil/stuff_test.go

66 lines
1.2 KiB
Go
Raw 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, 11)
2019-11-01 22:53:54 +03:00
files, err := decls.Files()
r.NoError(err)
for _, f := range files {
2019-11-05 19:44:15 +03:00
if f.Path.Pkg == ref.Module.Path {
r.Equal("app", f.Path.Pkg)
} else {
r.NotEqual("app", f.Path.Pkg)
}
2019-11-01 22:53:54 +03:00
}
r.Len(files, 25)
2019-11-01 22:53:54 +03:00
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)
}