github.com/nkprince007/lab@v0.6.2-0.20171218071646-19d68b56f403/cmd/issueCreate_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"os/exec"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func Test_issueCreate(t *testing.T) {
    12  	repo := copyTestRepo(t)
    13  	cmd := exec.Command("../lab_bin", "issue", "create", "lab-testing",
    14  		"-m", "issue title")
    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/")
    24  }
    25  
    26  func Test_issueMsg(t *testing.T) {
    27  	tests := []struct {
    28  		Name          string
    29  		Msgs          []string
    30  		ExpectedTitle string
    31  		ExpectedBody  string
    32  	}{
    33  		{
    34  			Name:          "Using messages",
    35  			Msgs:          []string{"issue title", "issue body", "issue body 2"},
    36  			ExpectedTitle: "issue title",
    37  			ExpectedBody:  "issue body\n\nissue body 2",
    38  		},
    39  		{
    40  			Name:          "From Editor",
    41  			Msgs:          nil,
    42  			ExpectedTitle: "I am the issue tmpl",
    43  			ExpectedBody:  "",
    44  		},
    45  	}
    46  	for _, test := range tests {
    47  		t.Run(test.Name, func(t *testing.T) {
    48  			test := test
    49  			t.Parallel()
    50  			title, body, err := issueMsg(test.Msgs)
    51  			if err != nil {
    52  				t.Fatal(err)
    53  			}
    54  			assert.Equal(t, test.ExpectedTitle, title)
    55  			assert.Equal(t, test.ExpectedBody, body)
    56  		})
    57  	}
    58  }
    59  
    60  func Test_issueText(t *testing.T) {
    61  	text, err := issueText()
    62  	if err != nil {
    63  		t.Fatal(err)
    64  	}
    65  	require.Equal(t, `
    66  
    67  I am the issue tmpl
    68  # Write a message for this issue. The first block
    69  # of text is the title and the rest is the description.`, text)
    70  
    71  }