Skip to content

Commit

Permalink
mr: Add approve and unapprove tests
Browse files Browse the repository at this point in the history
Add tests for the 'lab mr approve' and 'lab mr unapprove' command.

Also, remove capital 'U' on unapproved message.

Signed-off-by: Prarit Bhargava <[email protected]>
  • Loading branch information
prarit committed Dec 1, 2020
1 parent 46cef78 commit e19c7e1
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 32 deletions.
64 changes: 64 additions & 0 deletions cmd/mr_approve_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package cmd

import (
"os/exec"
"testing"

"github.com/acarl005/stripansi"
"github.com/stretchr/testify/require"
)

// https://gitlab.com/zaquestion/test/-/merge_requests/18 was opened for these
// tests

func Test_mrApproveSetup(t *testing.T) {
t.Parallel()
repo := copyTestRepo(t)
orig := exec.Command(labBinaryPath, "mr", "show", "18")
orig.Dir = repo

b, err := orig.CombinedOutput()
if err != nil {
t.Log(string(b))
t.Error(err)
}

origOutput := string(b)
origOutput = stripansi.Strip(origOutput)

require.Contains(t, origOutput, `Approved By: None`)
}

func Test_mrApprove(t *testing.T) {
repo := copyTestRepo(t)
orig := exec.Command(labBinaryPath, "mr", "approve", "18")
orig.Dir = repo

b, err := orig.CombinedOutput()
if err != nil {
t.Log(string(b))
t.Error(err)
}

origOutput := string(b)
origOutput = stripansi.Strip(origOutput)

require.Contains(t, origOutput, `Merge Request #18 approved`)
}

func Test_mrUnapprove(t *testing.T) {
repo := copyTestRepo(t)
orig := exec.Command(labBinaryPath, "mr", "unapprove", "18")
orig.Dir = repo

b, err := orig.CombinedOutput()
if err != nil {
t.Log(string(b))
t.Error(err)
}

origOutput := string(b)
origOutput = stripansi.Strip(origOutput)

require.Contains(t, origOutput, `Merge Request #18 unapproved`)
}
31 changes: 0 additions & 31 deletions cmd/mr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,37 +76,6 @@ func Test_mrCmd(t *testing.T) {
require.Contains(t, outStripped, "mr description")
require.Contains(t, out, fmt.Sprintf("WebURL: https://gitlab.com/lab-testing/test/-/merge_requests/%s", mrID))
})
// Users cannot approve and unapprove their own MRs. Comment out
// these tests for now until a better solution can be found.
//
//t.Run("approve", func(t *testing.T) {
// if mrID == "" {
// t.Skip("mrID is empty, create likely failed")
// }
// cmd := exec.Command(labBinaryPath, "mr", "lab-testing", "approve", mrID)
// cmd.Dir = repo
//
// //b, err := cmd.CombinedOutput()
// if err != nil {
// t.Log(string(b))
// t.Fatal(err)
// }
// require.Contains(t, string(b), fmt.Sprintf("Merge Request #%s approved", mrID))
//})
//t.Run("unapprove", func(t *testing.T) {
// if mrID == "" {
// t.Skip("mrID is empty, create likely failed")
// }
// cmd := exec.Command(labBinaryPath, "mr", "lab-testing", "unapprove", mrID)
// cmd.Dir = repo
//
// b, err := cmd.CombinedOutput()
// if err != nil {
// t.Log(string(b))
// t.Fatal(err)
// }
// require.Contains(t, string(b), fmt.Sprintf("Merge Request #%s unapproved", mrID))
//})
t.Run("delete", func(t *testing.T) {
if mrID == "" {
t.Skip("mrID is empty, create likely failed")
Expand Down
2 changes: 1 addition & 1 deletion cmd/mr_unapprove.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var mrUnapproveCmd = &cobra.Command{
if err != nil {
log.Fatal(err)
}
fmt.Printf("Merge Request #%d Unapproved\n", id)
fmt.Printf("Merge Request #%d unapproved\n", id)
},
}

Expand Down

0 comments on commit e19c7e1

Please sign in to comment.