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

     1  package cmd
     2  
     3  import (
     4  	"os/exec"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func Test_mrListAssignedTo(t *testing.T) {
    13  	t.Parallel()
    14  	repo := copyTestRepo(t)
    15  	cmd := exec.Command(labBinaryPath, "mr", "list", "--assignee=zaquestion")
    16  	cmd.Dir = repo
    17  
    18  	b, err := cmd.CombinedOutput()
    19  	if err != nil {
    20  		t.Fatal(err)
    21  	}
    22  
    23  	mrs := strings.Split(string(b), "\n")
    24  	t.Log(mrs)
    25  	require.Contains(t, mrs, "!1 Test MR for lab list")
    26  	require.NotContains(t, mrs, "!3")
    27  	require.NotContains(t, mrs, "filtering with labels and lists")
    28  }
    29  
    30  func Test_mrList(t *testing.T) {
    31  	t.Parallel()
    32  	repo := copyTestRepo(t)
    33  	cmd := exec.Command(labBinaryPath, "mr", "list")
    34  	cmd.Dir = repo
    35  
    36  	b, err := cmd.CombinedOutput()
    37  	if err != nil {
    38  		t.Fatal(err)
    39  	}
    40  
    41  	mrs := strings.Split(string(b), "\n")
    42  	t.Log(mrs)
    43  	require.Contains(t, mrs, "!1 Test MR for lab list")
    44  }
    45  
    46  func Test_mrListFlagLabel(t *testing.T) {
    47  	t.Parallel()
    48  	repo := copyTestRepo(t)
    49  	cmd := exec.Command(labBinaryPath, "mr", "list", "-l", "confirmed")
    50  	cmd.Dir = repo
    51  
    52  	b, err := cmd.CombinedOutput()
    53  	if err != nil {
    54  		t.Fatal(err)
    55  	}
    56  
    57  	mrs := strings.Split(string(b), "\n")
    58  	t.Log(mrs)
    59  	require.Contains(t, mrs, "!3 for testings filtering with labels and lists")
    60  }
    61  
    62  func Test_mrListStateMerged(t *testing.T) {
    63  	t.Parallel()
    64  	repo := copyTestRepo(t)
    65  	cmd := exec.Command(labBinaryPath, "mr", "list", "-s", "merged")
    66  	cmd.Dir = repo
    67  
    68  	b, err := cmd.CombinedOutput()
    69  	if err != nil {
    70  		t.Fatal(err)
    71  	}
    72  
    73  	mrs := strings.Split(string(b), "\n")
    74  	t.Log(mrs)
    75  	require.Contains(t, mrs, "!4 merged merge request")
    76  }
    77  
    78  func Test_mrListStateClosed(t *testing.T) {
    79  	t.Parallel()
    80  	repo := copyTestRepo(t)
    81  	cmd := exec.Command(labBinaryPath, "mr", "list", "-n", "1", "-s", "closed")
    82  	cmd.Dir = repo
    83  
    84  	b, err := cmd.CombinedOutput()
    85  	if err != nil {
    86  		t.Fatal(err)
    87  	}
    88  	require.Regexp(t, `!\d+`, string(b))
    89  }
    90  
    91  func Test_mrListFivePerPage(t *testing.T) {
    92  	t.Parallel()
    93  	repo := copyTestRepo(t)
    94  	cmd := exec.Command(labBinaryPath, "mr", "list", "-n", "5")
    95  	cmd.Dir = repo
    96  
    97  	b, err := cmd.CombinedOutput()
    98  	if err != nil {
    99  		t.Fatal(err)
   100  	}
   101  	mrs := getAppOutput(b)
   102  	require.Len(t, mrs, 5)
   103  }
   104  
   105  func Test_mrFilterByTargetBranch(t *testing.T) {
   106  	t.Parallel()
   107  	repo := copyTestRepo(t)
   108  	cmd := exec.Command(labBinaryPath, "mr", "list", "-t", "non-existing")
   109  	cmd.Dir = repo
   110  
   111  	b, err := cmd.CombinedOutput()
   112  	if err != nil {
   113  		t.Fatal(err)
   114  	}
   115  
   116  	mrs := getAppOutput(b)
   117  	assert.Empty(t, mrs, "Expected to find no MRs for non-existent branch")
   118  }
   119  
   120  var (
   121  	latestCreatedTestMR = "!968 README: dummy commit for CI tests"
   122  	latestUpdatedTestMR = "!329 MR for assign and review commands"
   123  )
   124  
   125  func Test_mrListByTargetBranch(t *testing.T) {
   126  	t.Parallel()
   127  	repo := copyTestRepo(t)
   128  	cmd := exec.Command(labBinaryPath, "mr", "list", "-t", "master")
   129  	cmd.Dir = repo
   130  
   131  	b, err := cmd.CombinedOutput()
   132  	if err != nil {
   133  		t.Fatal(err)
   134  	}
   135  
   136  	mrs := strings.Split(string(b), "\n")
   137  	require.Equal(t, latestUpdatedTestMR, mrs[0])
   138  }
   139  
   140  // updated,asc
   141  // !1
   142  func Test_mrListUpdatedAscending(t *testing.T) {
   143  	t.Parallel()
   144  	repo := copyTestRepo(t)
   145  	cmd := exec.Command(labBinaryPath, "mr", "list", "--number=1", "--order=updated_at", "--sort=asc")
   146  	cmd.Dir = repo
   147  
   148  	b, err := cmd.CombinedOutput()
   149  	if err != nil {
   150  		t.Fatal(err)
   151  	}
   152  
   153  	mrs := strings.Split(string(b), "\n")
   154  	t.Log(mrs)
   155  	require.Contains(t, mrs, "!3 for testings filtering with labels and lists")
   156  }
   157  
   158  // updatead,desc
   159  // !18
   160  func Test_mrListUpdatedDescending(t *testing.T) {
   161  	t.Parallel()
   162  	repo := copyTestRepo(t)
   163  	cmd := exec.Command(labBinaryPath, "mr", "list", "--number=1", "--order=updated_at", "--sort=desc")
   164  	cmd.Dir = repo
   165  
   166  	b, err := cmd.CombinedOutput()
   167  	if err != nil {
   168  		t.Fatal(err)
   169  	}
   170  
   171  	mrs := strings.Split(string(b), "\n")
   172  	t.Log(mrs)
   173  	require.Equal(t, latestUpdatedTestMR, mrs[0])
   174  }
   175  
   176  // created,asc
   177  // !1
   178  func Test_mrListCreatedAscending(t *testing.T) {
   179  	t.Parallel()
   180  	repo := copyTestRepo(t)
   181  	cmd := exec.Command(labBinaryPath, "mr", "list", "--number=1", "--order=created_at", "--sort=asc")
   182  	cmd.Dir = repo
   183  
   184  	b, err := cmd.CombinedOutput()
   185  	if err != nil {
   186  		t.Fatal(err)
   187  	}
   188  
   189  	mrs := strings.Split(string(b), "\n")
   190  	t.Log(mrs)
   191  	require.Contains(t, mrs, "!1 Test MR for lab list")
   192  }
   193  
   194  // created,desc
   195  // !18
   196  func Test_mrListCreatedDescending(t *testing.T) {
   197  	t.Parallel()
   198  	repo := copyTestRepo(t)
   199  	cmd := exec.Command(labBinaryPath, "mr", "list", "--number=1", "--order=created_at", "--sort=desc")
   200  	cmd.Dir = repo
   201  
   202  	b, err := cmd.CombinedOutput()
   203  	if err != nil {
   204  		t.Fatal(err)
   205  	}
   206  
   207  	mrs := strings.Split(string(b), "\n")
   208  	t.Log(mrs)
   209  	require.Equal(t, latestCreatedTestMR, mrs[0])
   210  }
   211  
   212  func Test_mrListSearch(t *testing.T) {
   213  	t.Parallel()
   214  	repo := copyTestRepo(t)
   215  	cmd := exec.Command(labBinaryPath, "mr", "list", "emoji")
   216  	cmd.Dir = repo
   217  
   218  	b, err := cmd.CombinedOutput()
   219  	if err != nil {
   220  		t.Fatal(err)
   221  	}
   222  
   223  	mrs := strings.Split(string(b), "\n")
   224  	t.Log(mrs)
   225  	require.Contains(t, mrs, "!6 test award emoji")
   226  }