Skip to content

Commit

Permalink
Merge pull request #648 from prarit/fix_tests
Browse files Browse the repository at this point in the history
Update mr_test.go to fix test failure case
  • Loading branch information
bmeneg authored Mar 26, 2021
2 parents 645c7e8 + 0f4aeea commit b7be9f9
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions cmd/mr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,26 @@ 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("sh", "-c", fmt.Sprintf("%s mr list %s | grep -m1 \"%s\" | cut -c2- | awk '{print $1}'", labBinaryPath, 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
openMRstr, err := openMRcmd.CombinedOutput()
openMRout, err := openMRcmd.CombinedOutput()
if err != nil {
t.Log(string(openMRstr))
t.Fatal(err)
t.Log(string(openMRout))
}

openMR, err := strconv.Atoi(strings.TrimSpace(string(openMRstr)))
// find MR number
s := strings.Split(string(openMRout), " ")
openMRstr := s[0]
// strip off "!"
openMRstr = openMRstr[1:]

openMR, err := strconv.Atoi(openMRstr)
if err != nil {
t.Log(string(openMRstr))
return
Expand All @@ -56,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 @@ -119,7 +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, "")
})
t.Run("create MR from file", func(t *testing.T) {
git := exec.Command("git", "checkout", "mrtest")
Expand Down Expand Up @@ -214,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 @@ -250,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 @@ -378,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 @@ -428,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 b7be9f9

Please sign in to comment.