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

     1  package cmd
     2  
     3  import (
     4  	"os/exec"
     5  	"testing"
     6  
     7  	"github.com/acarl005/stripansi"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func Test_mrShow(t *testing.T) {
    12  	t.Parallel()
    13  	repo := copyTestRepo(t)
    14  
    15  	// a comment has been added to
    16  	// https://gitlab.com/zaquestion/test/-/merge_requests/1 for this test
    17  	cmd := exec.Command(labBinaryPath, "mr", "show", "1", "--comments")
    18  	cmd.Dir = repo
    19  
    20  	b, err := cmd.CombinedOutput()
    21  	if err != nil {
    22  		t.Log(string(b))
    23  		t.Error(err)
    24  	}
    25  
    26  	out := string(b)
    27  	require.Contains(t, out, `!1 Test MR for lab list
    28  ===================================
    29  This MR is to remain open for testing the `+"`lab mr list`"+` functionality
    30  -----------------------------------
    31  Project: zaquestion/test
    32  Branches: mrtest->master
    33  Status: Open
    34  Assignee: zaquestion
    35  Author: zaquestion
    36  Approved By: None
    37  Approvers: None
    38  Approval Groups: None
    39  Reviewers: None
    40  Milestone: None
    41  Labels: documentation
    42  Issues Closed by this MR: 
    43  Subscribed: Yes
    44  WebURL: https://gitlab.com/zaquestion/test/-/merge_requests/1`)
    45  	require.Contains(t, string(b), `commented at`)
    46  	require.Contains(t, string(b), `updated comment at`)
    47  }
    48  
    49  func Test_mrShow_patch(t *testing.T) {
    50  	t.Parallel()
    51  	repo := copyTestRepo(t)
    52  	cmd := exec.Command(labBinaryPath, "mr", "show", "origin", "1", "--patch")
    53  	cmd.Dir = repo
    54  
    55  	b, err := cmd.CombinedOutput()
    56  	if err != nil {
    57  		t.Log(string(b))
    58  		t.Error(err)
    59  	}
    60  
    61  	out := string(b)
    62  	out = stripansi.Strip(out)
    63  	// The index line below has been stripped as it is dependent on
    64  	// the git version and pretty defaults.
    65  	require.Contains(t, out, `commit 54fd49a2ac60aeeef5ddc75efecd49f85f7ba9b0
    66  Author: Zaq? Wiedmann <zaquestion@gmail.com>
    67  Date:   Tue Sep 19 03:55:16 2017 +0000
    68  
    69      Test file for MR test
    70  
    71  diff --git a/mrtest b/mrtest
    72  new file mode 100644
    73  `)
    74  }
    75  
    76  func Test_mrShow_diffs(t *testing.T) {
    77  	t.Parallel()
    78  	repo := copyTestRepo(t)
    79  	coCmd := exec.Command(labBinaryPath, "mr", "checkout", "17")
    80  	coCmd.Dir = repo
    81  	coCmdOutput, err := coCmd.CombinedOutput()
    82  	if err != nil {
    83  		t.Log(string(coCmdOutput))
    84  		t.Error(err)
    85  	}
    86  
    87  	cmd := exec.Command(labBinaryPath, "mr", "show", "origin", "17", "--comments")
    88  	cmd.Dir = repo
    89  
    90  	b, err := cmd.CombinedOutput()
    91  	if err != nil {
    92  		t.Log(string(b))
    93  		t.Error(err)
    94  	}
    95  
    96  	out := string(b)
    97  	out = stripansi.Strip(out)
    98  
    99  	coCmd = exec.Command("git", "checkout", "master")
   100  	coCmd.Dir = repo
   101  	coCmdOutput, err = coCmd.CombinedOutput()
   102  	if err != nil {
   103  		t.Log(string(coCmdOutput))
   104  		t.Error(err)
   105  	}
   106  
   107  	require.Contains(t, out, `
   108  commit:5f4397445f620e1a6f22e0ce59e18cbf22f0ddff
   109  File:test
   110  |        @@ -5,7 +5,7 @@
   111  |  5   5  
   112  |  6   6  line 6 This is a test file with some text in it.
   113  |  7   7  
   114  |  8     -line 8 This is the second test line in the file.
   115  |      8 +line 8 This is an edit of line 8.
   116  
   117      This is a comment on the deleted line 8.
   118  `)
   119  
   120  	require.Contains(t, out, `
   121  commit:5f4397445f620e1a6f22e0ce59e18cbf22f0ddff
   122  File:test
   123  |  6   6  line 6 This is a test file with some text in it.
   124  |  7   7  
   125  |  8     -line 8 This is the second test line in the file.
   126  |      8 +line 8 This is an edit of line 8.
   127  |  9   9  
   128  | 10  10  line 10 This is the third line in the file.
   129  
   130      This is a comment on line 10.
   131  `)
   132  }