Skip to content

Commit

Permalink
mr_test: Add wildcard support to cleanupMR()
Browse files Browse the repository at this point in the history
The problem with cmd/mr_test.go:cleanupMR() is that the way
it is called is insufficient to clean up a failed test. The
sequence that is leading to failures is, for example,

test run #1:

Test_mrCmd() runs.
Test_mrCmd_MR_description_and_options() runs and fails leaving,
for example, a Merge Request with description "Fancy Description".
test run #1 fails.

test run #2:
Test_mrCmd() runs and fails because a Merge Request with
description "Fancy Description" exists. It is not "found" by
the cleanupMR() function because Test_mrCmd()'s call is looking
for a description of "mr title".
test run #2 fails.

test run #3

(with my changes from the first commit) cleans things up.
test run #3 fails.

test run #4 should succeed.

This is a painful way to test.  Since only one MR is created at a time for
the test branch the code should just clean up any existing MR.

Add wildcard support to the cleanupMR() function.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
  • Loading branch information
prarit committed Mar 25, 2021
1 parent fc1356f commit 0f4aeea
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions cmd/mr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ func closeMR(t *testing.T, targetRepo string, cmdDir string, mrID string) {
}

func cleanupMR(t *testing.T, targetRepo string, cmdDir string, MRtitle string) {
openMRcmd := exec.Command(labBinaryPath, "mr", "list", targetRepo, MRtitle)
var openMRcmd *exec.Cmd

if MRtitle == "" {
openMRcmd = exec.Command(labBinaryPath, "mr", "list", targetRepo)
} else {
openMRcmd = exec.Command(labBinaryPath, "mr", "list", targetRepo, MRtitle)
}
openMRcmd.Dir = cmdDir
openMRout, err := openMRcmd.CombinedOutput()
if err != nil {
Expand Down Expand Up @@ -61,7 +67,7 @@ func Test_mrCmd(t *testing.T) {
repo := copyTestRepo(t)
var mrID string
t.Run("prepare", func(t *testing.T) {
cleanupMR(t, "lab-testing", repo, "mr title")
cleanupMR(t, "lab-testing", repo, "")
})
t.Run("create", func(t *testing.T) {
git := exec.Command("git", "checkout", "mrtest")
Expand Down Expand Up @@ -124,8 +130,7 @@ func Test_mrCmd_MR_description_and_options(t *testing.T) {
commentID string
)
t.Run("prepare", func(t *testing.T) {
cleanupMR(t, "lab-testing", repo, "Fancy Description")
cleanupMR(t, "lab-testing", repo, "Updated Description")
cleanupMR(t, "lab-testing", repo, "")
})
t.Run("create MR from file", func(t *testing.T) {
git := exec.Command("git", "checkout", "mrtest")
Expand Down Expand Up @@ -220,7 +225,7 @@ func Test_mrCmd_DifferingUpstreamBranchName(t *testing.T) {
repo := copyTestRepo(t)
var mrID string
t.Run("prepare", func(t *testing.T) {
cleanupMR(t, "lab-testing", repo, "mr title")
cleanupMR(t, "lab-testing", repo, "")
})
t.Run("create", func(t *testing.T) {
git := exec.Command("git", "checkout", "-b", "local/mrtest", "origin/mrtest")
Expand Down Expand Up @@ -256,7 +261,7 @@ func Test_mrCmd_Draft(t *testing.T) {
repo := copyTestRepo(t)
var mrID string
t.Run("prepare", func(t *testing.T) {
cleanupMR(t, "lab-testing", repo, "Test draft")
cleanupMR(t, "lab-testing", repo, "")
})
t.Run("create", func(t *testing.T) {
git := exec.Command("git", "checkout", "mrtest")
Expand Down Expand Up @@ -384,7 +389,7 @@ func Test_mrCmd_ByBranch(t *testing.T) {
repo := copyTestRepo(t)
var mrID string
t.Run("prepare", func(t *testing.T) {
cleanupMR(t, "lab-testing", repo, "mr by branch")
cleanupMR(t, "lab-testing", repo, "")
})
t.Run("create", func(t *testing.T) {
git := exec.Command("git", "checkout", "mrtest")
Expand Down Expand Up @@ -434,7 +439,7 @@ func Test_mrCmd_source(t *testing.T) {
repo := copyTestRepo(t)
var mrID string
t.Run("prepare", func(t *testing.T) {
cleanupMR(t, "lab-testing", repo, "mr title")
cleanupMR(t, "lab-testing", repo, "")
})
t.Run("create_invalid", func(t *testing.T) {
git := exec.Command("git", "checkout", "mrtest")
Expand Down

0 comments on commit 0f4aeea

Please sign in to comment.