aboutsummaryrefslogtreecommitdiff
path: root/package_git_test.go
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 /package_git_test.go
parent12c26ac8c0bf7e0c70a189fe5c07c5590bf8d3f9 (diff)
downloadbeku-7dfb98090b2256d87c34eb842ff669724694ecde.tar.xz
[test] Add unit test for package addDep
Diffstat (limited to 'package_git_test.go')
-rw-r--r--package_git_test.go99
1 files changed, 99 insertions, 0 deletions
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)
}