Skip to content

Commit

Permalink
[#30] (issue/mr) test list
Browse files Browse the repository at this point in the history
  • Loading branch information
zaquestion committed Nov 12, 2017
1 parent a7715b2 commit 5b136f1
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go_import_path: github.com/zaquestion/lab
sudo: false

script:
- go test ./...
- make test

deploy:
provider: script
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test:
bash -c "trap 'trap - SIGINT SIGTERM ERR; mv testdata/.git testdata/test.git; exit 1' SIGINT SIGTERM ERR; $(MAKE) internal-test"

internal-test:
mv testdata/test.git testdata/.git
go test ./...
mv testdata/.git testdata/test.git

25 changes: 25 additions & 0 deletions cmd/issueList_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"os/exec"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func Test_issueList(t *testing.T) {
repo := copyTestRepo(t)
cmd := exec.Command("../lab_bin", "issue", "list")
cmd.Dir = repo

b, err := cmd.CombinedOutput()
if err != nil {
t.Fatal(err)
}

issues := strings.Split(string(b), "\n")
t.Log(issues)
firstIssue := issues[len(issues)-2 : len(issues)-1]
require.Equal(t, "#1 test issue for lab list", firstIssue[0])
}
25 changes: 25 additions & 0 deletions cmd/mrList_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"os/exec"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func Test_mrList(t *testing.T) {
repo := copyTestRepo(t)
cmd := exec.Command("../lab_bin", "mr", "list")
cmd.Dir = repo

b, err := cmd.CombinedOutput()
if err != nil {
t.Fatal(err)
}

issues := strings.Split(string(b), "\n")
t.Log(issues)
firstIssue := issues[len(issues)-2 : len(issues)-1]
require.Equal(t, "#1 Test MR for lab list", firstIssue[0])
}
17 changes: 3 additions & 14 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,9 @@ func TestMain(m *testing.M) {
log.Fatal(err)
}
rand.Seed(time.Now().UnixNano())
if _, err := os.Stat("_test"); os.IsNotExist(err) {

err = exec.Command("git", "clone", "https://gitlab.com/zaquestion/test.git", "_test").Run()
if err != nil {
log.Fatal(err)
}
err = exec.Command("sed", "-i", "s|https://gitlab.com/|git@gitlab.com:|", "_test/.git/config").Run()
if err != nil {
log.Fatal(err)
}
}
code := m.Run()
os.Remove("lab_bin")
testdirs, err := filepath.Glob("_test-*")
testdirs, err := filepath.Glob("testdata-*")
if err != nil {
log.Fatal(err)
}
Expand All @@ -54,9 +43,9 @@ func TestMain(m *testing.M) {
}

func copyTestRepo(t *testing.T) string {
dir := "_test-" + strconv.Itoa(int(rand.Uint64()))
dir := "testdata-" + strconv.Itoa(int(rand.Uint64()))
t.Log(dir)
err := exec.Command("cp", "-r", "_test", dir).Run()
err := exec.Command("cp", "-r", "testdata", dir).Run()
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 0 additions & 4 deletions internal/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ func TestMain(m *testing.M) {
if err != nil {
log.Fatal(err)
}
os.Rename("test.git", ".git")
code := m.Run()
os.Rename(".git", "test.git")
os.Exit(code)
}

func TestGitDir(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func init() {
// If the default user is being set this is the first time lab
// is being run.
if errt != nil {
fmt.Print("Enter default GitLab token: ")
fmt.Print("Enter default GitLab token (scope: api ): \nCreate here: https://gitlab.com/profile/personal_access_tokens")
token, err = reader.ReadString('\n')
token = token[:len(token)-1]
if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions internal/gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ func TestMain(m *testing.M) {
if err != nil {
log.Fatal(err)
}
os.Rename("test.git", ".git")
code := m.Run()
os.Rename(".git", "test.git")
os.Exit(code)
}

func TestLoadGitLabTmplMR(t *testing.T) {
mrTmpl := LoadGitLabTmpl(TmplMR)
require.Equal(t, mrTmpl, "I am the mr tmpl")
}

func TestLoadGitLabTmpl(t *testing.T) {
func TestLoadGitLabTmplIssue(t *testing.T) {
issueTmpl := LoadGitLabTmpl(TmplIssue)
require.Equal(t, issueTmpl, "I am the issue tmpl")
}
6 changes: 5 additions & 1 deletion testdata/test.git/config
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
bare = false
logallrefupdates = true
[remote "origin"]
url = git@github.com:zaquestion/lab.git
url = git@gitlab.com:zaquestion/test.git
fetch = +refs/heads/*:refs/remotes/origin/*
[gitlab]
token = uDz6czYV412zK-xC5mUu
user = lab-testing
host = https://gitlab.com
Binary file modified testdata/test.git/index
Binary file not shown.

0 comments on commit 5b136f1

Please sign in to comment.