diff --git a/here/dir.go b/here/dir.go index b830bc4..379f114 100644 --- a/here/dir.go +++ b/here/dir.go @@ -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 -} \ No newline at end of file +} diff --git a/here/dir_test.go b/here/dir_test.go new file mode 100644 index 0000000..3455767 --- /dev/null +++ b/here/dir_test.go @@ -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) + + }) + } +} diff --git a/pkging/mem/add_test.go b/pkging/mem/add_test.go index 249f3fd..342d048 100644 --- a/pkging/mem/add_test.go +++ b/pkging/mem/add_test.go @@ -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 diff --git a/pkging/pkgtest/ref.go b/pkging/pkgtest/ref.go index 003e22a..fa421ad 100644 --- a/pkging/pkgtest/ref.go +++ b/pkging/pkgtest/ref.go @@ -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) } diff --git a/pkging/pkgtest/testdata/ref/go.mod b/pkging/pkgtest/testdata/ref/go.mod index cc3b1a5..18f4f20 100644 --- a/pkging/pkgtest/testdata/ref/go.mod +++ b/pkging/pkgtest/testdata/ref/go.mod @@ -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 => ../../../../ diff --git a/pkging/pkgutil/stuff_test.go b/pkging/pkgutil/stuff_test.go index 7d4294a..e4975ee 100644 --- a/pkging/pkgutil/stuff_test.go +++ b/pkging/pkgutil/stuff_test.go @@ -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) -}