Skip to content

Commit

Permalink
mr_test: Add separate test case for different upstream name
Browse files Browse the repository at this point in the history
Commit 434587b piggy-backed the test case on top of the existing
"create MR from file" test; instead, add an explicit test case for
resolving the local branch to the correct upstream branch / MR ID.
  • Loading branch information
fmuellner authored and prarit committed Dec 11, 2020
1 parent 568d297 commit 32fd380
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions cmd/mr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,60 @@ func Test_mrCmd_MR_description_and_options(t *testing.T) {
})
}

func Test_mrCmd_DifferingUpstreamBranchName(t *testing.T) {
repo := copyTestRepo(t)
var mrID string
t.Run("prepare", func(t *testing.T) {
cmd := exec.Command("sh", "-c", labBinaryPath+` mr list lab-testing | grep -m1 'mr title' | cut -c2- | awk '{print $1}' | xargs `+labBinaryPath+` mr lab-testing -d`)
cmd.Dir = repo

b, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(b))
//t.Fatal(err)
}
})
t.Run("create", func(t *testing.T) {
git := exec.Command("git", "checkout", "-b", "local/mrtest", "origin/mrtest")
git.Dir = repo
b, err := git.CombinedOutput()
if err != nil {
t.Log(string(b))
t.Fatal(err)
}

cmd := exec.Command(labBinaryPath, "mr", "create", "lab-testing", "master",
"-m", "mr title",
"-m", "mr description",
"-a", "lab-testing",
)
cmd.Dir = repo

b, _ = cmd.CombinedOutput()
out := string(b)
t.Log(out)
require.Contains(t, out, "https://gitlab.com/lab-testing/test/-/merge_requests")

i := strings.Index(out, "/diffs\n")
mrID = strings.TrimPrefix(out[:i], "https://gitlab.com/lab-testing/test/-/merge_requests/")
t.Log(mrID)
})
t.Run("delete", func(t *testing.T) {
if mrID == "" {
t.Skip("mrID is empty, create likely failed")
}
cmd := exec.Command(labBinaryPath, "mr", "close", "lab-testing", 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 closed", mrID))
})
}

func Test_mrCmd_noArgs(t *testing.T) {
repo := copyTestRepo(t)
cmd := exec.Command(labBinaryPath, "mr")
Expand Down

0 comments on commit 32fd380

Please sign in to comment.