github.com/zaquestion/lab@v0.25.1/cmd/issue_note_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"os/exec"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func Test_issueCreateNote(t *testing.T) {
    12  	repo := copyTestRepo(t)
    13  	cmd := exec.Command(labBinaryPath, "issue", "note", "lab-testing", "1",
    14  		"-m", "note text")
    15  	cmd.Dir = repo
    16  
    17  	b, err := cmd.CombinedOutput()
    18  	if err != nil {
    19  		t.Log(string(b))
    20  		t.Fatal(err)
    21  	}
    22  
    23  	require.Contains(t, string(b), "https://gitlab.com/lab-testing/test/issues/1#note_")
    24  }
    25  
    26  func Test_issueReplyNote(t *testing.T) {
    27  	repo := copyTestRepo(t)
    28  	create := exec.Command(labBinaryPath, "issue", "create", "lab-testing", "-m", "note text")
    29  	create.Dir = repo
    30  
    31  	a, err := create.CombinedOutput()
    32  	if err != nil {
    33  		t.Log(string(a))
    34  		t.Fatal(err)
    35  	}
    36  	issueIDs := strings.Split(string(a), "\n")
    37  	issueID := strings.TrimPrefix(issueIDs[0], "https://gitlab.com/lab-testing/test/-/issues/")
    38  
    39  	note := exec.Command(labBinaryPath, "issue", "note", "lab-testing", issueID, "-m", "note text")
    40  	note.Dir = repo
    41  
    42  	b, err := note.CombinedOutput()
    43  	if err != nil {
    44  		t.Log(string(b))
    45  		t.Fatal(err)
    46  	}
    47  	_noteIDs := strings.Split(string(b), "\n")
    48  	noteIDs := strings.Split(_noteIDs[0], "#note_")
    49  	noteID := noteIDs[1]
    50  
    51  	// add reply to the noteID
    52  	reply := exec.Command(labBinaryPath, "issue", "reply", "lab-testing", issueID+":"+noteID,
    53  		"-m", "reply to note", "-m", "second reply paragraph")
    54  	reply.Dir = repo
    55  	c, err := reply.CombinedOutput()
    56  	if err != nil {
    57  		t.Log(string(c))
    58  		t.Fatal(err)
    59  	}
    60  	_replyIDs := strings.Split(string(c), "\n")
    61  	replyIDs := strings.Split(_replyIDs[0], "#note_")
    62  	replyID := replyIDs[1]
    63  
    64  	show := exec.Command(labBinaryPath, "issue", "show", "lab-testing", issueID, "--comments")
    65  	show.Dir = repo
    66  	d, err := show.CombinedOutput()
    67  	if err != nil {
    68  		t.Log(string(d))
    69  		t.Fatal(err)
    70  	}
    71  
    72  	require.Contains(t, string(d), "#"+noteID+": "+"lab-testing started a discussion")
    73  	require.Contains(t, string(d), "#"+replyID+": "+"lab-testing commented at")
    74  	require.Contains(t, string(d), "    reply to note")
    75  	require.Contains(t, string(d), "    second reply paragraph")
    76  }