diff options
| author | Shulhan <ms@kilabit.info> | 2018-05-17 06:12:59 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2018-05-17 06:12:59 +0700 |
| commit | efa4f97627b70ccba2f98574090abd751bc11d83 (patch) | |
| tree | 394041ae3a0cb212c7d57f999bc785c212be7914 /package_test.go | |
| parent | b6e72ab41aa1ab207cb255d38158271634e558ae (diff) | |
| download | beku-efa4f97627b70ccba2f98574090abd751bc11d83.tar.xz | |
[test] Move test initialization and common test functions to beku_test
Diffstat (limited to 'package_test.go')
| -rw-r--r-- | package_test.go | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/package_test.go b/package_test.go index e225bc5..f8dafea 100644 --- a/package_test.go +++ b/package_test.go @@ -85,3 +85,101 @@ func TestIsEqual(t *testing.T) { test.Assert(t, "", c.exp, got, true) } } + +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 +} |
