aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2018-05-17 05:50:22 +0700
committerShulhan <ms@kilabit.info>2018-05-17 05:50:22 +0700
commit7dfb98090b2256d87c34eb842ff669724694ecde (patch)
tree540f84be0ebd20584b9b08737127d3d6f6cdc7fd
parent12c26ac8c0bf7e0c70a189fe5c07c5590bf8d3f9 (diff)
downloadbeku-7dfb98090b2256d87c34eb842ff669724694ecde.tar.xz
[test] Add unit test for package addDep
-rw-r--r--package.go4
-rw-r--r--package_git_test.go99
2 files changed, 101 insertions, 2 deletions
diff --git a/package.go b/package.go
index b19eb07..ea5030a 100644
--- a/package.go
+++ b/package.go
@@ -199,8 +199,8 @@ func (pkg *Package) GetRecursiveImports() (
// (4.1) if match found, link the package deps to existing package instance.
// (4.2) If no match found, add to `depsMissing` as string
//
-// It will return true if import path is added as link or missing; otherwise
-// it will return false.
+// It will return true if import path is added as dependencies or as missing
+// one; otherwise it will return false.
//
func (pkg *Package) addDep(env *Env, importPath string) bool {
// (0)
diff --git a/package_git_test.go b/package_git_test.go
index 8665187..193cffb 100644
--- a/package_git_test.go
+++ b/package_git_test.go
@@ -283,6 +283,104 @@ func testGitScanDeps(t *testing.T) {
}
}
+func testAddDep(t *testing.T) {
+ cases := []struct {
+ desc string
+ envPkgs []*Package
+ importPath string
+ exp bool
+ expDeps []string
+ expDepsMissing []string
+ expPkgsMissing []string
+ }{{
+ desc: "Is the same path as package",
+ importPath: testGitRepo,
+ }, {
+ desc: "Is vendor package",
+ importPath: "vendor/github.com/shuLhan/beku",
+ }, {
+ desc: "Is standard package",
+ importPath: "os/exec",
+ }, {
+ desc: "Is exist on environment",
+ envPkgs: []*Package{{
+ ImportPath: "github.com/shuLhan/beku",
+ }, {
+ ImportPath: "github.com/shuLhan/share",
+ }},
+ importPath: "github.com/shuLhan/share/lib/test",
+ exp: true,
+ expDeps: []string{
+ "github.com/shuLhan/share",
+ },
+ }, {
+ desc: "Is exist on environment (again)",
+ envPkgs: []*Package{{
+ ImportPath: "github.com/shuLhan/beku",
+ }, {
+ ImportPath: "github.com/shuLhan/share",
+ }},
+ importPath: "github.com/shuLhan/share/lib/test",
+ exp: true,
+ expDeps: []string{
+ "github.com/shuLhan/share",
+ },
+ }, {
+ desc: "Is not exist on environment (missing)",
+ importPath: "github.com/shuLhan/tekstus",
+ exp: true,
+ expDeps: []string{
+ "github.com/shuLhan/share",
+ },
+ expDepsMissing: []string{
+ "github.com/shuLhan/tekstus",
+ },
+ expPkgsMissing: []string{
+ "github.com/shuLhan/tekstus",
+ },
+ }, {
+ desc: "Is not exist on environment (again)",
+ importPath: "github.com/shuLhan/tekstus",
+ exp: true,
+ expDeps: []string{
+ "github.com/shuLhan/share",
+ },
+ expDepsMissing: []string{
+ "github.com/shuLhan/tekstus",
+ },
+ expPkgsMissing: []string{
+ "github.com/shuLhan/tekstus",
+ },
+ }}
+
+ var got bool
+
+ gitCurPkg.Deps = nil
+ gitCurPkg.DepsMissing = nil
+
+ for _, c := range cases {
+ t.Log(c.desc)
+
+ testEnv.pkgs = c.envPkgs
+ testEnv.pkgsMissing = nil
+ got = gitCurPkg.addDep(testEnv, c.importPath)
+
+ test.Assert(t, "return", c.exp, got, true)
+
+ if !got {
+ continue
+ }
+
+ test.Assert(t, "Deps", c.expDeps, gitCurPkg.Deps, true)
+ test.Assert(t, "DepsMissing", c.expDepsMissing, gitCurPkg.DepsMissing, true)
+ test.Assert(t, "env.pkgsMissing", c.expPkgsMissing,
+ testEnv.pkgsMissing, true)
+ }
+
+ gitCurPkg.Deps = nil
+ gitCurPkg.DepsMissing = nil
+}
+
func TestGit(t *testing.T) {
orgGOPATH := build.Default.GOPATH
@@ -319,4 +417,5 @@ func TestGit(t *testing.T) {
t.Run("Fetch", testGitFetch)
t.Run("Scan", testGitScan)
t.Run("ScanDeps", testGitScanDeps)
+ t.Run("addDep", testAddDep)
}