mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/186 This is an ongoing work for fixing #61 (Github issue) Reviewed By: alexsn Differential Revision: D18672982 fbshipit-source-id: 12051d7b06d87d73d37b68382566732e532193e3
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"golang.org/x/tools/go/packages/packagestest"
|
|
)
|
|
|
|
func TestPkgPath(t *testing.T) { packagestest.TestAll(t, testPkgPath) }
|
|
func testPkgPath(t *testing.T, x packagestest.Exporter) {
|
|
e := packagestest.Export(t, x, []packagestest.Module{
|
|
{
|
|
Name: "golang.org/x",
|
|
Files: map[string]interface{}{
|
|
"x.go": "package x",
|
|
"y/y.go": "package y",
|
|
},
|
|
},
|
|
})
|
|
defer e.Cleanup()
|
|
|
|
e.Config.Dir = filepath.Dir(e.File("golang.org/x", "x.go"))
|
|
target := filepath.Join(e.Config.Dir, "ent")
|
|
pkgPath, err := PkgPath(e.Config, target)
|
|
require.NoError(t, err)
|
|
require.Equal(t, "golang.org/x/ent", pkgPath)
|
|
|
|
e.Config.Dir = filepath.Dir(e.File("golang.org/x", "y/y.go"))
|
|
target = filepath.Join(e.Config.Dir, "ent")
|
|
pkgPath, err = PkgPath(e.Config, target)
|
|
require.NoError(t, err)
|
|
require.Equal(t, "golang.org/x/y/ent", pkgPath)
|
|
|
|
target = filepath.Join(e.Config.Dir, "z/ent")
|
|
pkgPath, err = PkgPath(e.Config, target)
|
|
require.Error(t, err)
|
|
require.Empty(t, pkgPath)
|
|
}
|