stabilize tests

This commit is contained in:
Mark Bates 2019-11-10 17:22:01 -05:00
parent b4f921bd19
commit 2a9f9649bb
6 changed files with 40 additions and 76 deletions

View File

@ -36,10 +36,10 @@ func Dir(p string) (Info, error) {
if err != nil {
es := err.Error()
if (strings.Contains(es, "cannot find module for path .") || strings.Contains(es, "no Go files") || strings.Contains(es, "can't load package")) {
if strings.Contains(es, "cannot find module for path .") || strings.Contains(es, "no Go files") || strings.Contains(es, "can't load package") {
if _, err := os.Stat(fmt.Sprintf("%s/go.mod", p)); err == nil {
var mod Module
bm, err := run ("go", "list", "-m", "-json")
bm, err := run("go", "list", "-m", "-json")
if err != nil {
return i, err
}
@ -92,4 +92,4 @@ func prepareInfo(p string, info Info, target *Info) {
ph = filepath.Join(info.Module.Dir, ph)
target.Dir = ph
}
}

33
here/dir_test.go Normal file
View File

@ -0,0 +1,33 @@
package here_test
import (
"testing"
"github.com/markbates/pkger/pkging/pkgtest"
"github.com/stretchr/testify/require"
)
func Test_Dir(t *testing.T) {
r := require.New(t)
ref, err := pkgtest.NewRef()
r.NoError(err)
table := []struct {
in string
err bool
}{
{in: ref.Dir, err: false},
}
for _, tt := range table {
t.Run(tt.in, func(st *testing.T) {
r := require.New(st)
if tt.err {
r.Error(err)
}
r.NoError(err)
})
}
}

View File

@ -20,7 +20,7 @@ func Test_Pkger_Add(t *testing.T) {
r.NoError(err)
var exp []os.FileInfo
root := filepath.Join(cur.Dir, "pkging", "pkgtest", "testdata", "ref", "cmd-main")
root := filepath.Join(cur.Dir, "pkging", "pkgtest", "testdata", "ref")
err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err

View File

@ -16,23 +16,6 @@ type Ref struct {
root string
}
func NewRefOnlyMod() (*Ref, error) {
her, err := here.Package("github.com/markbates/pkger")
if err != nil {
return nil, err
}
root := filepath.Join(
her.Module.Dir,
"pkging",
"pkgtest",
"testdata",
"ref",
"cmd-main")
return newRef(root)
}
func NewRef() (*Ref, error) {
her, err := here.Package("github.com/markbates/pkger")
if err != nil {
@ -45,7 +28,7 @@ func NewRef() (*Ref, error) {
"pkgtest",
"testdata",
"ref",
"root-main")
)
return newRef(root)
}

View File

@ -2,6 +2,6 @@ module app
go 1.13
require github.com/markbates/pkger v0.8.0
require github.com/markbates/pkger v0.0.0
replace github.com/markbates/pkger => ../../../../../
replace github.com/markbates/pkger => ../../../../

View File

@ -63,55 +63,3 @@ func Test_Stuff(t *testing.T) {
_, err = pkg.Stat("/public/index.html")
r.NoError(err)
}
func Test_Stuff_With_GoMod_Without_GoFiles(t *testing.T) {
r := require.New(t)
ref, err := pkgtest.NewRefOnlyMod()
r.NoError(err)
defer os.RemoveAll(ref.Dir)
disk, err := stdos.New(ref.Info)
r.NoError(err)
infos, err := pkgtest.LoadFiles("/", ref, disk)
r.NoError(err)
r.Len(infos, 19)
decls, err := parser.Parse(ref.Info)
r.NoError(err)
r.Len(decls, 1)
files, err := decls.Files()
r.NoError(err)
for _, f := range files {
if f.Path.Pkg == ref.Module.Path {
r.Equal("app", f.Path.Pkg)
} else {
r.NotEqual("app", f.Path.Pkg)
}
}
r.Len(files, 4)
bb := &bytes.Buffer{}
err = Stuff(bb, ref.Info, decls)
r.NoError(err)
pkg, err := mem.UnmarshalEmbed(bb.Bytes())
r.NoError(err)
pkgtest.CurrentTest(t, ref, pkg)
pkgtest.InfoTest(t, ref, pkg)
pkgtest.OpenTest(t, ref, pkg)
pkgtest.WalkTest(t, ref, pkg)
_, err = pkg.Stat("/go.mod")
r.NoError(err)
_, err = pkg.Stat("/public/index.html")
r.NoError(err)
}