aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2018-09-14 21:39:50 +0700
committerShulhan <ms@kilabit.info>2018-09-14 21:39:50 +0700
commitb79333cfadb9145811441a2cf002e578d9651d2c (patch)
tree4ba71be211b68c0d40fbb9609c62c695a23648d2
parentd16a0e48c4f6812cf5c12cf42d68ac418e7a8276 (diff)
downloadbeku-b79333cfadb9145811441a2cf002e578d9651d2c.tar.xz
Refactoring test to use clone from local directory
-rw-r--r--beku_test.go49
-rw-r--r--env_test.go7
-rw-r--r--package_test.go42
-rw-r--r--testdata/beku_test.git/HEAD1
-rw-r--r--testdata/beku_test.git/config6
-rw-r--r--testdata/beku_test.git/description1
-rw-r--r--testdata/beku_test.git/objects/pack/pack-6968a14165fc3c53cfcc3b1282019c96d19b6923.idxbin0 -> 1408 bytes
-rw-r--r--testdata/beku_test.git/objects/pack/pack-6968a14165fc3c53cfcc3b1282019c96d19b6923.packbin0 -> 1016 bytes
-rw-r--r--testdata/beku_test.git/packed-refs5
9 files changed, 67 insertions, 44 deletions
diff --git a/beku_test.go b/beku_test.go
index 29492d3..987264f 100644
--- a/beku_test.go
+++ b/beku_test.go
@@ -7,9 +7,11 @@ package beku
import (
"fmt"
"go/build"
+ "log"
"os"
"testing"
+ "github.com/shuLhan/share/lib/debug"
"github.com/shuLhan/share/lib/test/mock"
)
@@ -18,17 +20,18 @@ const (
testDBSaveExclude = "testdata/beku.db.exclude"
testGitRepo = "github.com/shuLhan/beku_test"
testGitRepoVersion = "c9f69fb"
- testGitRepoShare = "github.com/shuLhan/share"
testPkgNotExist = "github.com/shuLhan/notexist"
)
var (
- testEnv *Env
- testGitPkgCur *Package
- testGitPkgNew *Package
- testGitPkgShare *Package
- testStdout *os.File
- testStderr *os.File
+ testEnv *Env
+ testGitPkgCur *Package
+ testGitPkgNew *Package
+ testGitPkgInstall *Package
+ testStdout *os.File
+ testStderr *os.File
+
+ testGitRepoSrcLocal = "/testdata/beku_test.git"
)
func TestMain(m *testing.M) {
@@ -36,8 +39,7 @@ func TestMain(m *testing.M) {
testGOPATH, err := os.Getwd()
if err != nil {
- fmt.Fprintln(os.Stderr, err)
- os.Exit(1)
+ log.Fatal(err)
}
testGOPATH += "/testdata"
@@ -52,26 +54,31 @@ func TestMain(m *testing.M) {
testEnv, err = NewEnvironment(false, false)
if err != nil {
- fmt.Fprintln(os.Stderr, err)
- os.Exit(1)
+ log.Fatal(err)
}
testGitPkgCur, _ = NewPackage(testEnv, testGitRepo, testGitRepo)
testGitPkgNew, _ = NewPackage(testEnv, testGitRepo, testGitRepo)
- testGitPkgShare, _ = NewPackage(testEnv, testGitRepoShare, testGitRepoShare)
+ testGitPkgInstall, _ = NewPackage(testEnv, testGitRepo, testGitRepo)
- // Always set the git test repo to latest version.
- testEnv.NoConfirm = true
- err = testEnv.Sync(testGitRepo, testGitRepo)
+ wd, err := os.Getwd()
if err != nil {
- fmt.Fprintln(os.Stderr, err)
- os.Exit(1)
+ log.Fatal(err)
+ }
+
+ testGitRepoSrcLocal = "file://" + wd + testGitRepoSrcLocal
+ testGitPkgInstall.RemoteURL = testGitRepoSrcLocal
+
+ if debug.Value >= 1 {
+ fmt.Printf("test env : %+v\n", *testEnv)
+ fmt.Printf("testGitPkgCur: %+v\n", *testGitPkgCur)
+ fmt.Printf("testGitPkgNew: %+v\n", *testGitPkgNew)
}
- testEnv.NoConfirm = false
- fmt.Printf("test env : %+v\n", *testEnv)
- fmt.Printf("testGitPkgCur: %+v\n", *testGitPkgCur)
- fmt.Printf("testGitPkgNew: %+v\n", *testGitPkgNew)
+ err = testGitPkgInstall.Install()
+ if err != nil {
+ log.Fatal(err)
+ }
os.Exit(m.Run())
}
diff --git a/env_test.go b/env_test.go
index d287b03..6cb933a 100644
--- a/env_test.go
+++ b/env_test.go
@@ -10,6 +10,7 @@ import (
"path/filepath"
"testing"
+ "github.com/shuLhan/share/lib/debug"
"github.com/shuLhan/share/lib/test"
"github.com/shuLhan/share/lib/test/mock"
"github.com/shuLhan/tekstus/diff"
@@ -448,7 +449,9 @@ func testEnvSave(t *testing.T) {
t.Fatal(err)
}
- fmt.Printf("diffs: %s\n", diffs)
+ if debug.Value >= 1 {
+ fmt.Printf("diffs: %s\n", diffs)
+ }
}
}
@@ -496,7 +499,7 @@ func testEnvScan(t *testing.T) {
FullPath: filepath.Join(testEnv.dirSrc, testGitRepo),
ScanPath: filepath.Join(testEnv.dirSrc, testGitRepo),
RemoteName: "origin",
- RemoteURL: "https://github.com/shuLhan/beku_test",
+ RemoteURL: testGitRepoSrcLocal,
RemoteBranch: "master",
Version: "v0.2.0",
isTag: true,
diff --git a/package_test.go b/package_test.go
index 00d603e..0d73dfc 100644
--- a/package_test.go
+++ b/package_test.go
@@ -27,7 +27,7 @@ func testPackageRemove(t *testing.T) {
pkgName: testPkgNotExist,
}, {
desc: `Package exist`,
- pkg: testGitPkgShare,
+ pkg: testGitPkgInstall,
}}
for _, c := range cases {
@@ -67,13 +67,13 @@ func testPackageInstall(t *testing.T) {
expPkg *Package
}{{
desc: `Without version`,
- pkg: testGitPkgShare,
+ pkg: testGitPkgInstall,
expPkg: &Package{
- ImportPath: testGitRepoShare,
- ScanPath: testGitPkgShare.FullPath,
- FullPath: testGitPkgShare.FullPath,
+ ImportPath: testGitRepo,
+ ScanPath: testGitPkgInstall.FullPath,
+ FullPath: testGitPkgInstall.FullPath,
RemoteName: gitDefRemoteName,
- RemoteURL: "https://" + testGitRepoShare,
+ RemoteURL: testGitPkgInstall.RemoteURL,
RemoteBranch: "master",
Version: "157a004",
vcsMode: VCSModeGit,
@@ -81,7 +81,7 @@ func testPackageInstall(t *testing.T) {
},
}, {
desc: `Install again`,
- pkg: testGitPkgShare,
+ pkg: testGitPkgInstall,
expErr: "gitInstall: Clone: exit status 128",
}}
@@ -285,16 +285,16 @@ func testPushRequiredBy(t *testing.T) {
expRequiredBy []string
}{{
desc: "Not exist yet",
- importPath: testGitRepoShare,
+ importPath: testGitRepo,
exp: true,
expRequiredBy: []string{
- testGitRepoShare,
+ testGitRepo,
},
}, {
desc: "Already exist",
- importPath: testGitRepoShare,
+ importPath: testGitRepo,
expRequiredBy: []string{
- testGitRepoShare,
+ testGitRepo,
},
}}
@@ -326,12 +326,12 @@ func testPackageRemoveRequiredBy(t *testing.T) {
importPath: testPkgNotExist,
exp: false,
expRequiredBy: []string{
- testGitRepoShare,
+ testGitRepo,
},
}, {
desc: `With importPath found`,
pkg: testGitPkgCur,
- importPath: testGitRepoShare,
+ importPath: testGitRepo,
exp: true,
}}
@@ -521,7 +521,7 @@ func testPackageString(t *testing.T) {
ScanPath = ` + filepath.Join(testEnv.dirSrc, testGitRepo) + `
VCS = git
RemoteName = origin
- RemoteURL = https://` + testGitRepo + `
+ RemoteURL = ` + testGitRepoSrcLocal + `
RemoteBranch = master
Version = v0.2.0
VersionNext =
@@ -559,14 +559,14 @@ func testUpdate(t *testing.T) {
ImportPath: testGitRepo,
FullPath: filepath.Join(testEnv.dirSrc, testGitRepo),
RemoteName: gitDefRemoteName,
- RemoteURL: "git@github.com:shuLhan/beku_test.git",
+ RemoteURL: testGitRepoSrcLocal,
},
expPkg: &Package{
vcsMode: VCSModeGit,
ImportPath: testGitRepo,
FullPath: filepath.Join(testEnv.dirSrc, testGitRepo),
RemoteName: gitDefRemoteName,
- RemoteURL: "git@github.com:shuLhan/beku_test.git",
+ RemoteURL: testGitRepoSrcLocal,
},
}, {
desc: "Update version",
@@ -582,7 +582,7 @@ func testUpdate(t *testing.T) {
ImportPath: testGitRepo,
FullPath: filepath.Join(testEnv.dirSrc, testGitRepo),
RemoteName: gitDefRemoteName,
- RemoteURL: "git@github.com:shuLhan/beku_test.git",
+ RemoteURL: testGitRepoSrcLocal,
Version: "v0.1.0",
isTag: true,
},
@@ -591,7 +591,7 @@ func testUpdate(t *testing.T) {
ImportPath: testGitRepo,
FullPath: filepath.Join(testEnv.dirSrc, testGitRepo),
RemoteName: gitDefRemoteName,
- RemoteURL: "git@github.com:shuLhan/beku_test.git",
+ RemoteURL: testGitRepoSrcLocal,
Version: "v0.1.0",
isTag: true,
},
@@ -609,7 +609,7 @@ func testUpdate(t *testing.T) {
ImportPath: testGitRepo,
FullPath: filepath.Join(testEnv.dirSrc, testGitRepo),
RemoteName: gitDefRemoteName,
- RemoteURL: "git@github.com:shuLhan/beku_test.git",
+ RemoteURL: testGitRepoSrcLocal,
Version: "c9f69fb",
isTag: true,
},
@@ -618,7 +618,7 @@ func testUpdate(t *testing.T) {
ImportPath: testGitRepo,
FullPath: filepath.Join(testEnv.dirSrc, testGitRepo),
RemoteName: gitDefRemoteName,
- RemoteURL: "git@github.com:shuLhan/beku_test.git",
+ RemoteURL: testGitRepoSrcLocal,
Version: "c9f69fb",
isTag: false,
},
@@ -765,7 +765,7 @@ func testPackageGoClean(t *testing.T) {
}
func testPackagePost(t *testing.T) {
- err := testGitPkgShare.Remove()
+ err := testGitPkgInstall.Remove()
if err != nil {
t.Fatal(err)
}
diff --git a/testdata/beku_test.git/HEAD b/testdata/beku_test.git/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/testdata/beku_test.git/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/testdata/beku_test.git/config b/testdata/beku_test.git/config
new file mode 100644
index 0000000..a730278
--- /dev/null
+++ b/testdata/beku_test.git/config
@@ -0,0 +1,6 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
+[remote "origin"]
+ url = /home/ms/src/github.com/shuLhan/share/lib/git/testdata/beku_test
diff --git a/testdata/beku_test.git/description b/testdata/beku_test.git/description
new file mode 100644
index 0000000..498b267
--- /dev/null
+++ b/testdata/beku_test.git/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/testdata/beku_test.git/objects/pack/pack-6968a14165fc3c53cfcc3b1282019c96d19b6923.idx b/testdata/beku_test.git/objects/pack/pack-6968a14165fc3c53cfcc3b1282019c96d19b6923.idx
new file mode 100644
index 0000000..794afbb
--- /dev/null
+++ b/testdata/beku_test.git/objects/pack/pack-6968a14165fc3c53cfcc3b1282019c96d19b6923.idx
Binary files differ
diff --git a/testdata/beku_test.git/objects/pack/pack-6968a14165fc3c53cfcc3b1282019c96d19b6923.pack b/testdata/beku_test.git/objects/pack/pack-6968a14165fc3c53cfcc3b1282019c96d19b6923.pack
new file mode 100644
index 0000000..4f4e14e
--- /dev/null
+++ b/testdata/beku_test.git/objects/pack/pack-6968a14165fc3c53cfcc3b1282019c96d19b6923.pack
Binary files differ
diff --git a/testdata/beku_test.git/packed-refs b/testdata/beku_test.git/packed-refs
new file mode 100644
index 0000000..c014ad2
--- /dev/null
+++ b/testdata/beku_test.git/packed-refs
@@ -0,0 +1,5 @@
+# pack-refs with: peeled fully-peeled sorted
+d6ad9dabc61f72558013bb05e91bf273c491e39c refs/heads/beku
+c9f69fb7fea72fbc0e7b70a82a1a48a6e89c4ee0 refs/heads/master
+ec65455bf4ca8c37a65ce88b9385e4191fb21975 refs/tags/v0.1.0
+582b912d9958422308dd6aaca85bc15a0463086e refs/tags/v0.2.0