diff --git a/Makefile b/Makefile index ca0b87de..87f3e8c4 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/cmd/issueCreate_test.go b/cmd/issueCreate_test.go index fd3a066a..5a8d99f7 100644 --- a/cmd/issueCreate_test.go +++ b/cmd/issueCreate_test.go @@ -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) diff --git a/cmd/mrCreate_test.go b/cmd/mrCreate_test.go index cf9dbe15..b38ec6cd 100644 --- a/cmd/mrCreate_test.go +++ b/cmd/mrCreate_test.go @@ -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") @@ -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`) + +} diff --git a/cmd/root_test.go b/cmd/root_test.go index 49db7366..9c15ebba 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -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 { @@ -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) } @@ -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.") } diff --git a/testdata/test.git/MERGE_RR b/testdata/test.git/MERGE_RR deleted file mode 100644 index e69de29b..00000000 diff --git a/testdata/test.git/index b/testdata/test.git/index index d8b8a43e..e9209c62 100644 Binary files a/testdata/test.git/index and b/testdata/test.git/index differ diff --git a/testdata/test.git/logs/HEAD b/testdata/test.git/logs/HEAD index 90f7677f..8569d11d 100644 --- a/testdata/test.git/logs/HEAD +++ b/testdata/test.git/logs/HEAD @@ -1,2 +1,5 @@ 0000000000000000000000000000000000000000 d0e1cc068b44c9622f9046faf24f53b57980e53c Zaq? Wiedmann 1504410153 -0700 commit (initial): Add test readme for testing gitlog d0e1cc068b44c9622f9046faf24f53b57980e53c cd64a7caea4f3ee5696a190379aff1a7f636e598 Zaq? Wiedmann 1504411119 -0700 commit: Added additional commit for LastCommitMessage and meeting requirements for Log test (>1 commit) +cd64a7caea4f3ee5696a190379aff1a7f636e598 54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0 Zaq? Wiedmann 1512509254 -0800 checkout: moving from master to origin/mrtest +54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0 54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0 Zaq? Wiedmann 1512509258 -0800 checkout: moving from 54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0 to mrtest +54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0 cd64a7caea4f3ee5696a190379aff1a7f636e598 Zaq? Wiedmann 1512509349 -0800 checkout: moving from mrtest to master diff --git a/testdata/test.git/logs/refs/heads/mrtest b/testdata/test.git/logs/refs/heads/mrtest new file mode 100644 index 00000000..f573ce46 --- /dev/null +++ b/testdata/test.git/logs/refs/heads/mrtest @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0 Zaq? Wiedmann 1512509258 -0800 branch: Created from HEAD diff --git a/testdata/test.git/refs/heads/mrtest b/testdata/test.git/refs/heads/mrtest new file mode 100644 index 00000000..a734a155 --- /dev/null +++ b/testdata/test.git/refs/heads/mrtest @@ -0,0 +1 @@ +54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0