summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorDenis Palashevskii <palash.denis@outlook.com>2021-04-21 16:43:10 +0400
committerJesse Duffield <jessedduffield@gmail.com>2021-07-27 21:30:08 +1000
commit755cc9f8d895647d2373a7eca784f45f72f26201 (patch)
tree5cce59a248327a7c5d2e9c88b1d043d50fd17da6 /pkg/commands
parent0e6598adbd7c5321c3e9ec46d303a707d0e5ecbb (diff)
Add tests
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/pull_request_test.go111
1 files changed, 104 insertions, 7 deletions
diff --git a/pkg/commands/pull_request_test.go b/pkg/commands/pull_request_test.go
index eb9b173ae..0413022d6 100644
--- a/pkg/commands/pull_request_test.go
+++ b/pkg/commands/pull_request_test.go
@@ -48,7 +48,8 @@ func TestGetRepoInfoFromURL(t *testing.T) {
func TestCreatePullRequest(t *testing.T) {
type scenario struct {
testName string
- branch *models.Branch
+ from *models.Branch
+ to *models.Branch
remoteUrl string
command func(string, ...string) *exec.Cmd
test func(url string, err error)
@@ -57,7 +58,7 @@ func TestCreatePullRequest(t *testing.T) {
scenarios := []scenario{
{
testName: "Opens a link to new pull request on bitbucket",
- branch: &models.Branch{
+ from: &models.Branch{
Name: "feature/profile-page",
},
remoteUrl: "git@bitbucket.org:johndoe/social_network.git",
@@ -78,7 +79,7 @@ func TestCreatePullRequest(t *testing.T) {
},
{
testName: "Opens a link to new pull request on bitbucket with http remote url",
- branch: &models.Branch{
+ from: &models.Branch{
Name: "feature/events",
},
remoteUrl: "https://my_username@bitbucket.org/johndoe/social_network.git",
@@ -99,7 +100,7 @@ func TestCreatePullRequest(t *testing.T) {
},
{
testName: "Opens a link to new pull request on github",
- branch: &models.Branch{
+ from: &models.Branch{
Name: "feature/sum-operation",
},
remoteUrl: "git@github.com:peter/calculator.git",
@@ -119,8 +120,80 @@ func TestCreatePullRequest(t *testing.T) {
},
},
{
+ testName: "Opens a link to new pull request on bitbucket with specific target branch",
+ from: &models.Branch{
+ Name: "feature/profile-page/avatar",
+ },
+ to: &models.Branch{
+ Name: "feature/profile-page",
+ },
+ remoteUrl: "git@bitbucket.org:johndoe/social_network.git",
+ command: func(cmd string, args ...string) *exec.Cmd {
+ // Handle git remote url call
+ if strings.HasPrefix(cmd, "git") {
+ return secureexec.Command("echo", "git@bitbucket.org:johndoe/social_network.git")
+ }
+
+ assert.Equal(t, cmd, "open")
+ assert.Equal(t, args, []string{"https://bitbucket.org/johndoe/social_network/pull-requests/new?source=feature/profile-page/avatar&dest=feature/profile-page&t=1"})
+ return secureexec.Command("echo")
+ },
+ test: func(url string, err error) {
+ assert.NoError(t, err)
+ assert.Equal(t, "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=feature/profile-page/avatar&dest=feature/profile-page&t=1", url)
+ },
+ },
+ {
+ testName: "Opens a link to new pull request on bitbucket with http remote url with specified target branch",
+ from: &models.Branch{
+ Name: "feature/remote-events",
+ },
+ to: &models.Branch{
+ Name: "feature/events",
+ },
+ remoteUrl: "https://my_username@bitbucket.org/johndoe/social_network.git",
+ command: func(cmd string, args ...string) *exec.Cmd {
+ // Handle git remote url call
+ if strings.HasPrefix(cmd, "git") {
+ return secureexec.Command("echo", "https://my_username@bitbucket.org/johndoe/social_network.git")
+ }
+
+ assert.Equal(t, cmd, "open")
+ assert.Equal(t, args, []string{"https://bitbucket.org/johndoe/social_network/pull-requests/new?source=feature/remote-events&dest=feature/events&t=1"})
+ return secureexec.Command("echo")
+ },
+ test: func(url string, err error) {
+ assert.NoError(t, err)
+ assert.Equal(t, "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=feature/remote-events&dest=feature/events&t=1", url)
+ },
+ },
+ {
+ testName: "Opens a link to new pull request on github with specific target branch",
+ from: &models.Branch{
+ Name: "feature/sum-operation",
+ },
+ to: &models.Branch{
+ Name: "feature/operations",
+ },
+ remoteUrl: "git@github.com:peter/calculator.git",
+ command: func(cmd string, args ...string) *exec.Cmd {
+ // Handle git remote url call
+ if strings.HasPrefix(cmd, "git") {
+ return secureexec.Command("echo", "git@github.com:peter/calculator.git")
+ }
+
+ assert.Equal(t, cmd, "open")
+ assert.Equal(t, args, []string{"https://github.com/peter/calculator/compare/feature/operations...feature/sum-operation?expand=1"})
+ return secureexec.Command("echo")
+ },
+ test: func(url string, err error) {
+ assert.NoError(t, err)
+ assert.Equal(t, "https://github.com/peter/calculator/compare/feature/operations...feature/sum-operation?expand=1", url)
+ },
+ },
+ {
testName: "Opens a link to new pull request on gitlab",
- branch: &models.Branch{
+ from: &models.Branch{
Name: "feature/ui",
},
remoteUrl: "git@gitlab.com:peter/calculator.git",
@@ -140,8 +213,32 @@ func TestCreatePullRequest(t *testing.T) {
},
},
{
+ testName: "Opens a link to new pull request on gitlab with specific target branch",
+ from: &models.Branch{
+ Name: "feature/commit-ui",
+ },
+ to: &models.Branch{
+ Name: "epic/ui",
+ },
+ remoteUrl: "git@gitlab.com:peter/calculator.git",
+ command: func(cmd string, args ...string) *exec.Cmd {
+ // Handle git remote url call
+ if strings.HasPrefix(cmd, "git") {
+ return secureexec.Command("echo", "git@gitlab.com:peter/calculator.git")
+ }
+
+ assert.Equal(t, cmd, "open")
+ assert.Equal(t, args, []string{"https://gitlab.com/peter/calculator/merge_requests/new?merge_request[source_branch]=feature/commit-ui&merge_request[target_branch]=epic/ui"})
+ return secureexec.Command("echo")
+ },
+ test: func(url string, err error) {
+ assert.NoError(t, err)
+ assert.Equal(t, "https://gitlab.com/peter/calculator/merge_requests/new?merge_request[source_branch]=feature/commit-ui&merge_request[target_branch]=epic/ui", url)
+ },
+ },
+ {
testName: "Throws an error if git service is unsupported",
- branch: &models.Branch{
+ from: &models.Branch{
Name: "feature/divide-operation",
},
remoteUrl: "git@something.com:peter/calculator.git",
@@ -171,7 +268,7 @@ func TestCreatePullRequest(t *testing.T) {
return s.remoteUrl, nil
}
dummyPullRequest := NewPullRequest(gitCommand)
- s.test(dummyPullRequest.Create(s.branch))
+ s.test(dummyPullRequest.Create(s.from, s.to))
})
}
}