Skip to content

Commit

Permalink
Merge pull request #56 from zaquestion/tests-cmd
Browse files Browse the repository at this point in the history
(tests) mrText all non-integration (lab_bin) tests run in testdata to work with git operations
  • Loading branch information
zaquestion authored Dec 5, 2017
2 parents a248954 + 99e5400 commit e063a53
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ internal-test:
mv testdata/test.git testdata/.git
go test -coverprofile=coverage-git.out -covermode=count github.com/zaquestion/lab/internal/git
go test -coverprofile=coverage-gitlab.out -covermode=count github.com/zaquestion/lab/internal/gitlab
go test github.com/zaquestion/lab/cmd
go test -coverprofile=coverage-cmd.out -covermode=count github.com/zaquestion/lab/cmd
mv testdata/.git testdata/test.git
go get github.com/wadey/gocovmerge
gocovmerge coverage-*.out > coverage.txt && rm coverage-*.out
3 changes: 2 additions & 1 deletion cmd/issueCreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ func Test_issueText(t *testing.T) {
// since `issueText()` is being called from the `cmd` directory the
// underlying LoadGitLabTmpl call doesn't find a template.
// This is fine since we have other tests to test loading the template
assert.Equal(t, `
require.Equal(t, `
I am the issue tmpl
# Write a message for this issue. The first block
# of text is the title and the rest is the description.`, text)

Expand Down
34 changes: 26 additions & 8 deletions cmd/mrCreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@ import (

func Test_mrCreate(t *testing.T) {
repo := copyTestRepo(t)
git := exec.Command("git", "checkout", "origin/mrtest")

git := exec.Command("git", "checkout", "mrtest")
git.Dir = repo
out, err := git.CombinedOutput()
if err != nil {
t.Log(string(out))
t.Fatal(err)
}
git = exec.Command("git", "checkout", "-b", "mrtest")
git.Dir = repo
out, err = git.CombinedOutput()
if err != nil {
t.Log(string(out))
t.Fatal(err)
}

cmd := exec.Command("../lab_bin", "mr", "create", "lab-testing",
"-m", "mr title")
Expand All @@ -34,3 +28,27 @@ func Test_mrCreate(t *testing.T) {
// its good enough to assert lab is working
require.Contains(t, string(b), "409 {message: [Cannot Create: This merge request already exists: [\"mr title\"]]}")
}

func Test_mrText(t *testing.T) {
text, err := mrText("master", "mrtest", "lab-testing", "origin")
if err != nil {
t.Log(text)
t.Fatal(err)
}
// Normally we we expect the issue template to prefix this. However
// since `issueText()` is being called from the `cmd` directory the
// underlying LoadGitLabTmpl call doesn't find a template.
// This is fine since we have other tests to test loading the template
require.Contains(t, text, `Added additional commit for LastCommitMessage and meeting requirements for Log test (>1 commit)
I am the mr tmpl
# Requesting a merge into origin:master from lab-testing:mrtest
#
# Write a message for this merge request. The first block
# of text is the title and the rest is the description.
#
# Changes:
#
# 54fd49a (Zaq? Wiedmann`)

}
7 changes: 4 additions & 3 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ func TestMain(m *testing.M) {
log.Fatal(err)
}
rand.Seed(time.Now().UnixNano())
os.Chdir(path.Join(wd, "testdata"))
code := m.Run()
os.Chdir(wd)
os.Remove("lab_bin")
testdirs, err := filepath.Glob("testdata-*")
if err != nil {
Expand All @@ -43,9 +45,9 @@ func TestMain(m *testing.M) {
}

func copyTestRepo(t *testing.T) string {
dir := "testdata-" + strconv.Itoa(int(rand.Uint64()))
dir := "../testdata-" + strconv.Itoa(int(rand.Uint64()))
t.Log(dir)
err := exec.Command("cp", "-r", "testdata", dir).Run()
err := exec.Command("cp", "-r", "../testdata", dir).Run()
if err != nil {
t.Fatal(err)
}
Expand All @@ -59,7 +61,6 @@ func copyTestRepo(t *testing.T) string {

func TestRootCloneNoArg(t *testing.T) {
cmd := exec.Command("../lab_bin", "clone")
cmd.Dir = "./testdata"
b, _ := cmd.CombinedOutput()
require.Contains(t, string(b), "You must specify a repository to clone.")
}
Empty file removed testdata/test.git/MERGE_RR
Empty file.
Binary file modified testdata/test.git/index
Binary file not shown.
3 changes: 3 additions & 0 deletions testdata/test.git/logs/HEAD
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
0000000000000000000000000000000000000000 d0e1cc068b44c9622f9046faf24f53b57980e53c Zaq? Wiedmann <zaquestion@gmail.com> 1504410153 -0700 commit (initial): Add test readme for testing gitlog
d0e1cc068b44c9622f9046faf24f53b57980e53c cd64a7caea4f3ee5696a190379aff1a7f636e598 Zaq? Wiedmann <zaquestion@gmail.com> 1504411119 -0700 commit: Added additional commit for LastCommitMessage and meeting requirements for Log test (>1 commit)
cd64a7caea4f3ee5696a190379aff1a7f636e598 54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0 Zaq? Wiedmann <zaquestion@gmail.com> 1512509254 -0800 checkout: moving from master to origin/mrtest
54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0 54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0 Zaq? Wiedmann <zaquestion@gmail.com> 1512509258 -0800 checkout: moving from 54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0 to mrtest
54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0 cd64a7caea4f3ee5696a190379aff1a7f636e598 Zaq? Wiedmann <zaquestion@gmail.com> 1512509349 -0800 checkout: moving from mrtest to master
1 change: 1 addition & 0 deletions testdata/test.git/logs/refs/heads/mrtest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0000000000000000000000000000000000000000 54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0 Zaq? Wiedmann <zaquestion@gmail.com> 1512509258 -0800 branch: Created from HEAD
1 change: 1 addition & 0 deletions testdata/test.git/refs/heads/mrtest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0

0 comments on commit e063a53

Please sign in to comment.