Skip to content

Commit

Permalink
lab: Add tests for reply commands
Browse files Browse the repository at this point in the history
Add tests for 'lab issue reply' and 'lab mr reply'.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
  • Loading branch information
prarit committed Dec 6, 2020
1 parent f46c433 commit 8486750
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
50 changes: 50 additions & 0 deletions cmd/issue_note_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

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

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -53,6 +54,55 @@ func Test_issueNoteMsg(t *testing.T) {
}
}

func Test_issueReplyNote(t *testing.T) {
repo := copyTestRepo(t)
create := exec.Command(labBinaryPath, "issue", "create", "lab-testing", "-m", "note text")
create.Dir = repo

a, err := create.CombinedOutput()
if err != nil {
t.Log(string(a))
t.Fatal(err)
}
issueIDs := strings.Split(string(a), "\n")
issueID := strings.Trim(issueIDs[0], "https://gitlab.com/lab-testing/test/-/issues/")

note := exec.Command(labBinaryPath, "issue", "note", "lab-testing", issueID, "-m", "note text")
note.Dir = repo

b, err := note.CombinedOutput()
if err != nil {
t.Log(string(b))
t.Fatal(err)
}
_noteIDs := strings.Split(string(b), "\n")
noteIDs := strings.Split(_noteIDs[0], "#note_")
noteID := noteIDs[1]

// add reply to the noteID
reply := exec.Command(labBinaryPath, "issue", "reply", "lab-testing", issueID+":"+noteID, "-m", "reply to note")
reply.Dir = repo
c, err := reply.CombinedOutput()
if err != nil {
t.Log(string(c))
t.Fatal(err)
}
_replyIDs := strings.Split(string(c), "\n")
replyIDs := strings.Split(_replyIDs[0], "#note_")
replyID := replyIDs[1]

show := exec.Command(labBinaryPath, "issue", "show", "lab-testing", issueID, "--comments")
show.Dir = repo
d, err := show.CombinedOutput()
if err != nil {
t.Log(string(d))
t.Fatal(err)
}

require.Contains(t, string(d), "#"+noteID+": "+"lab-testing started a discussion")
require.Contains(t, string(d), "#"+replyID+": "+"lab-testing commented at")
}

func Test_issueNoteText(t *testing.T) {
t.Parallel()
text, err := noteText("\n")
Expand Down
49 changes: 49 additions & 0 deletions cmd/mr_note_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"os/exec"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -70,6 +71,54 @@ func Test_mrCreateNote_file(t *testing.T) {
require.Contains(t, string(b), "https://gitlab.com/lab-testing/test/merge_requests/1#note_")
}

func Test_mrReplyAndResolve(t *testing.T) {
repo := copyTestRepo(t)

cmd := exec.Command(labBinaryPath, "mr", "note", "lab-testing", "1", "-m", "merge request text")
cmd.Dir = repo

a, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(a))
t.Fatal(err)
}
_noteIDs := strings.Split(string(a), "\n")
noteIDs := strings.Split(_noteIDs[0], "#note_")
noteID := noteIDs[1]

// add reply to the noteID
reply := exec.Command(labBinaryPath, "mr", "reply", "lab-testing", "1:"+noteID, "-m", "reply to note")
reply.Dir = repo
c, err := reply.CombinedOutput()
if err != nil {
t.Log(string(c))
t.Fatal(err)
}
_replyIDs := strings.Split(string(c), "\n")
replyIDs := strings.Split(_replyIDs[0], "#note_")
replyID := replyIDs[1]

show := exec.Command(labBinaryPath, "mr", "show", "lab-testing", "1", "--comments")
show.Dir = repo
d, err := show.CombinedOutput()
if err != nil {
t.Log(string(d))
t.Fatal(err)
}

resolve := exec.Command(labBinaryPath, "mr", "resolve", "lab-testing", "1:"+noteID)
resolve.Dir = repo
e, err := resolve.CombinedOutput()
if err != nil {
t.Log(string(e))
t.Fatal(err)
}

require.Contains(t, string(d), "#"+noteID+": "+"lab-testing started a discussion")
require.Contains(t, string(d), "#"+replyID+": "+"lab-testing commented at")
require.Contains(t, string(e), "Resolved")
}

func Test_mrNoteMsg(t *testing.T) {
tests := []struct {
Name string
Expand Down

0 comments on commit 8486750

Please sign in to comment.