mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
Enable/disable os specific tests at compile time
This commit is contained in:
committed by
Jesse Duffield
parent
1e50764b4d
commit
7564e506b5
138
pkg/commands/oscommands/os_default_test.go
Normal file
138
pkg/commands/oscommands/os_default_test.go
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
//go:build !windows
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package oscommands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/secureexec"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestOSCommandOpenFileDarwin is a function.
|
||||||
|
func TestOSCommandOpenFileDarwin(t *testing.T) {
|
||||||
|
type scenario struct {
|
||||||
|
filename string
|
||||||
|
command func(string, ...string) *exec.Cmd
|
||||||
|
test func(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
scenarios := []scenario{
|
||||||
|
{
|
||||||
|
"test",
|
||||||
|
func(name string, arg ...string) *exec.Cmd {
|
||||||
|
return secureexec.Command("exit", "1")
|
||||||
|
},
|
||||||
|
func(err error) {
|
||||||
|
assert.Error(t, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test",
|
||||||
|
func(name string, arg ...string) *exec.Cmd {
|
||||||
|
assert.Equal(t, "bash", name)
|
||||||
|
assert.Equal(t, []string{"-c", `open "test"`}, arg)
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
func(err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"filename with spaces",
|
||||||
|
func(name string, arg ...string) *exec.Cmd {
|
||||||
|
assert.Equal(t, "bash", name)
|
||||||
|
assert.Equal(t, []string{"-c", `open "filename with spaces"`}, arg)
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
func(err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range scenarios {
|
||||||
|
OSCmd := NewDummyOSCommand()
|
||||||
|
OSCmd.Platform.OS = "darwin"
|
||||||
|
OSCmd.Command = s.command
|
||||||
|
OSCmd.Config.GetUserConfig().OS.OpenCommand = "open {{filename}}"
|
||||||
|
|
||||||
|
s.test(OSCmd.OpenFile(s.filename))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestOSCommandOpenFileLinux tests the OpenFile command on Linux
|
||||||
|
func TestOSCommandOpenFileLinux(t *testing.T) {
|
||||||
|
type scenario struct {
|
||||||
|
filename string
|
||||||
|
command func(string, ...string) *exec.Cmd
|
||||||
|
test func(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
scenarios := []scenario{
|
||||||
|
{
|
||||||
|
"test",
|
||||||
|
func(name string, arg ...string) *exec.Cmd {
|
||||||
|
return secureexec.Command("exit", "1")
|
||||||
|
},
|
||||||
|
func(err error) {
|
||||||
|
assert.Error(t, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test",
|
||||||
|
func(name string, arg ...string) *exec.Cmd {
|
||||||
|
assert.Equal(t, "bash", name)
|
||||||
|
assert.Equal(t, []string{"-c", `xdg-open "test" > /dev/null`}, arg)
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
func(err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"filename with spaces",
|
||||||
|
func(name string, arg ...string) *exec.Cmd {
|
||||||
|
assert.Equal(t, "bash", name)
|
||||||
|
assert.Equal(t, []string{"-c", `xdg-open "filename with spaces" > /dev/null`}, arg)
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
func(err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"let's_test_with_single_quote",
|
||||||
|
func(name string, arg ...string) *exec.Cmd {
|
||||||
|
assert.Equal(t, "bash", name)
|
||||||
|
assert.Equal(t, []string{"-c", `xdg-open "let's_test_with_single_quote" > /dev/null`}, arg)
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
func(err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$USER.txt",
|
||||||
|
func(name string, arg ...string) *exec.Cmd {
|
||||||
|
assert.Equal(t, "bash", name)
|
||||||
|
assert.Equal(t, []string{"-c", `xdg-open "\$USER.txt" > /dev/null`}, arg)
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
func(err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range scenarios {
|
||||||
|
OSCmd := NewDummyOSCommand()
|
||||||
|
OSCmd.Command = s.command
|
||||||
|
OSCmd.Platform.OS = "linux"
|
||||||
|
OSCmd.Config.GetUserConfig().OS.OpenCommand = `xdg-open {{filename}} > /dev/null`
|
||||||
|
|
||||||
|
s.test(OSCmd.OpenFile(s.filename))
|
||||||
|
}
|
||||||
|
}
|
@ -3,11 +3,8 @@ package oscommands
|
|||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"runtime"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/secureexec"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -60,214 +57,6 @@ func TestOSCommandRunCommand(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestOSCommandOpenFile is a function.
|
|
||||||
func TestOSCommandOpenFile(t *testing.T) {
|
|
||||||
type scenario struct {
|
|
||||||
filename string
|
|
||||||
command func(string, ...string) *exec.Cmd
|
|
||||||
test func(error)
|
|
||||||
}
|
|
||||||
|
|
||||||
scenarios := []scenario{
|
|
||||||
{
|
|
||||||
"test",
|
|
||||||
func(name string, arg ...string) *exec.Cmd {
|
|
||||||
return secureexec.Command("exit", "1")
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
assert.Error(t, err)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"test",
|
|
||||||
func(name string, arg ...string) *exec.Cmd {
|
|
||||||
assert.Equal(t, "bash", name)
|
|
||||||
assert.Equal(t, []string{"-c", `open "test"`}, arg)
|
|
||||||
return secureexec.Command("echo")
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
assert.NoError(t, err)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"filename with spaces",
|
|
||||||
func(name string, arg ...string) *exec.Cmd {
|
|
||||||
assert.Equal(t, "bash", name)
|
|
||||||
assert.Equal(t, []string{"-c", `open "filename with spaces"`}, arg)
|
|
||||||
return secureexec.Command("echo")
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
assert.NoError(t, err)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, s := range scenarios {
|
|
||||||
OSCmd := NewDummyOSCommand()
|
|
||||||
OSCmd.Platform.OS = "darwin"
|
|
||||||
OSCmd.Command = s.command
|
|
||||||
OSCmd.Config.GetUserConfig().OS.OpenCommand = "open {{filename}}"
|
|
||||||
|
|
||||||
s.test(OSCmd.OpenFile(s.filename))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestOSCommandOpenFileLinux tests the OpenFile command on Linux
|
|
||||||
func TestOSCommandOpenFileLinux(t *testing.T) {
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
type scenario struct {
|
|
||||||
filename string
|
|
||||||
command func(string, ...string) *exec.Cmd
|
|
||||||
test func(error)
|
|
||||||
}
|
|
||||||
|
|
||||||
scenarios := []scenario{
|
|
||||||
{
|
|
||||||
"test",
|
|
||||||
func(name string, arg ...string) *exec.Cmd {
|
|
||||||
return secureexec.Command("exit", "1")
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
assert.Error(t, err)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"test",
|
|
||||||
func(name string, arg ...string) *exec.Cmd {
|
|
||||||
assert.Equal(t, "bash", name)
|
|
||||||
assert.Equal(t, []string{"-c", "xdg-open \"test\" > /dev/null"}, arg)
|
|
||||||
return secureexec.Command("echo")
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
assert.NoError(t, err)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"filename with spaces",
|
|
||||||
func(name string, arg ...string) *exec.Cmd {
|
|
||||||
assert.Equal(t, "bash", name)
|
|
||||||
assert.Equal(t, []string{"-c", "xdg-open \"filename with spaces\" > /dev/null"}, arg)
|
|
||||||
return secureexec.Command("echo")
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
assert.NoError(t, err)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"let's_test_with_single_quote",
|
|
||||||
func(name string, arg ...string) *exec.Cmd {
|
|
||||||
assert.Equal(t, "bash", name)
|
|
||||||
assert.Equal(t, []string{"-c", "xdg-open \"let's_test_with_single_quote\" > /dev/null"}, arg)
|
|
||||||
return secureexec.Command("echo")
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
assert.NoError(t, err)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"$USER.txt",
|
|
||||||
func(name string, arg ...string) *exec.Cmd {
|
|
||||||
assert.Equal(t, "bash", name)
|
|
||||||
assert.Equal(t, []string{"-c", "xdg-open \"\\$USER.txt\" > /dev/null"}, arg)
|
|
||||||
return secureexec.Command("echo")
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
assert.NoError(t, err)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, s := range scenarios {
|
|
||||||
OSCmd := NewDummyOSCommand()
|
|
||||||
OSCmd.Command = s.command
|
|
||||||
OSCmd.Platform.OS = "linux"
|
|
||||||
OSCmd.Config.GetUserConfig().OS.OpenCommand = `xdg-open {{filename}} > /dev/null`
|
|
||||||
|
|
||||||
s.test(OSCmd.OpenFile(s.filename))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestOSCommandOpenFileWindows tests the OpenFile command on Linux
|
|
||||||
func TestOSCommandOpenFileWindows(t *testing.T) {
|
|
||||||
if runtime.GOOS != "windows" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
type scenario struct {
|
|
||||||
filename string
|
|
||||||
command func(string, ...string) *exec.Cmd
|
|
||||||
test func(error)
|
|
||||||
}
|
|
||||||
|
|
||||||
scenarios := []scenario{
|
|
||||||
{
|
|
||||||
"test",
|
|
||||||
func(name string, arg ...string) *exec.Cmd {
|
|
||||||
return secureexec.Command("exit", "1")
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
assert.Error(t, err)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"test",
|
|
||||||
func(name string, arg ...string) *exec.Cmd {
|
|
||||||
assert.Equal(t, "cmd", name)
|
|
||||||
assert.Equal(t, []string{"/c", "start", "", "test"}, arg)
|
|
||||||
return secureexec.Command("echo")
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
assert.NoError(t, err)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"filename with spaces",
|
|
||||||
func(name string, arg ...string) *exec.Cmd {
|
|
||||||
assert.Equal(t, "cmd", name)
|
|
||||||
assert.Equal(t, []string{"/c", "start", "", "filename with spaces"}, arg)
|
|
||||||
return secureexec.Command("echo")
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
assert.NoError(t, err)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"let's_test_with_single_quote",
|
|
||||||
func(name string, arg ...string) *exec.Cmd {
|
|
||||||
assert.Equal(t, "cmd", name)
|
|
||||||
assert.Equal(t, []string{"/c", "start", "", "let's_test_with_single_quote"}, arg)
|
|
||||||
return secureexec.Command("echo")
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
assert.NoError(t, err)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"$USER.txt",
|
|
||||||
func(name string, arg ...string) *exec.Cmd {
|
|
||||||
assert.Equal(t, "cmd", name)
|
|
||||||
assert.Equal(t, []string{"/c", "start", "", "$USER.txt"}, arg)
|
|
||||||
return secureexec.Command("echo")
|
|
||||||
},
|
|
||||||
func(err error) {
|
|
||||||
assert.NoError(t, err)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, s := range scenarios {
|
|
||||||
OSCmd := NewDummyOSCommand()
|
|
||||||
OSCmd.Command = s.command
|
|
||||||
OSCmd.Platform.OS = "windows"
|
|
||||||
OSCmd.Config.GetUserConfig().OS.OpenCommand = `cmd /c start "" {{filename}}`
|
|
||||||
|
|
||||||
s.test(OSCmd.OpenFile(s.filename))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestOSCommandQuote is a function.
|
// TestOSCommandQuote is a function.
|
||||||
func TestOSCommandQuote(t *testing.T) {
|
func TestOSCommandQuote(t *testing.T) {
|
||||||
osCommand := NewDummyOSCommand()
|
osCommand := NewDummyOSCommand()
|
||||||
|
86
pkg/commands/oscommands/os_windows_test.go
Normal file
86
pkg/commands/oscommands/os_windows_test.go
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
//go:build windows
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package oscommands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/secureexec"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestOSCommandOpenFileWindows tests the OpenFile command on Linux
|
||||||
|
func TestOSCommandOpenFileWindows(t *testing.T) {
|
||||||
|
type scenario struct {
|
||||||
|
filename string
|
||||||
|
command func(string, ...string) *exec.Cmd
|
||||||
|
test func(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
scenarios := []scenario{
|
||||||
|
{
|
||||||
|
"test",
|
||||||
|
func(name string, arg ...string) *exec.Cmd {
|
||||||
|
return secureexec.Command("exit", "1")
|
||||||
|
},
|
||||||
|
func(err error) {
|
||||||
|
assert.Error(t, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test",
|
||||||
|
func(name string, arg ...string) *exec.Cmd {
|
||||||
|
assert.Equal(t, "cmd", name)
|
||||||
|
assert.Equal(t, []string{"/c", "start", "", "test"}, arg)
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
func(err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"filename with spaces",
|
||||||
|
func(name string, arg ...string) *exec.Cmd {
|
||||||
|
assert.Equal(t, "cmd", name)
|
||||||
|
assert.Equal(t, []string{"/c", "start", "", "filename with spaces"}, arg)
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
func(err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"let's_test_with_single_quote",
|
||||||
|
func(name string, arg ...string) *exec.Cmd {
|
||||||
|
assert.Equal(t, "cmd", name)
|
||||||
|
assert.Equal(t, []string{"/c", "start", "", "let's_test_with_single_quote"}, arg)
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
func(err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$USER.txt",
|
||||||
|
func(name string, arg ...string) *exec.Cmd {
|
||||||
|
assert.Equal(t, "cmd", name)
|
||||||
|
assert.Equal(t, []string{"/c", "start", "", "$USER.txt"}, arg)
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
func(err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range scenarios {
|
||||||
|
OSCmd := NewDummyOSCommand()
|
||||||
|
OSCmd.Command = s.command
|
||||||
|
OSCmd.Platform.OS = "windows"
|
||||||
|
OSCmd.Config.GetUserConfig().OS.OpenCommand = `start "" {{filename}}`
|
||||||
|
|
||||||
|
s.test(OSCmd.OpenFile(s.filename))
|
||||||
|
}
|
||||||
|
}
|
258
pkg/commands/pull_request_default_test.go
Normal file
258
pkg/commands/pull_request_default_test.go
Normal file
@ -0,0 +1,258 @@
|
|||||||
|
//go:build !windows
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/secureexec"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestCreatePullRequest is a function.
|
||||||
|
func TestCreatePullRequest(t *testing.T) {
|
||||||
|
type scenario struct {
|
||||||
|
testName string
|
||||||
|
from string
|
||||||
|
to string
|
||||||
|
remoteUrl string
|
||||||
|
command func(string, ...string) *exec.Cmd
|
||||||
|
test func(url string, err error)
|
||||||
|
}
|
||||||
|
|
||||||
|
scenarios := []scenario{
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on bitbucket",
|
||||||
|
from: "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, "bash")
|
||||||
|
assert.Equal(t, args, []string{"-c", `open "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=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&t=1", url)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on bitbucket with http remote url",
|
||||||
|
from: "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, "bash")
|
||||||
|
assert.Equal(t, args, []string{"-c", `open "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=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/events&t=1", url)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on github",
|
||||||
|
from: "feature/sum-operation",
|
||||||
|
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, "bash")
|
||||||
|
assert.Equal(t, args, []string{"-c", `open "https://github.com/peter/calculator/compare/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/sum-operation?expand=1", url)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on bitbucket with specific target branch",
|
||||||
|
from: "feature/profile-page/avatar",
|
||||||
|
to: "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, "bash")
|
||||||
|
assert.Equal(t, args, []string{"-c", `open "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: "feature/remote-events",
|
||||||
|
to: "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, "bash")
|
||||||
|
assert.Equal(t, args, []string{"-c", `open "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: "feature/sum-operation",
|
||||||
|
to: "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, "bash")
|
||||||
|
assert.Equal(t, args, []string{"-c", `open "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",
|
||||||
|
from: "feature/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, "bash")
|
||||||
|
assert.Equal(t, args, []string{"-c", `open "https://gitlab.com/peter/calculator/merge_requests/new?merge_request[source_branch]=feature/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/ui", url)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on gitlab in nested groups",
|
||||||
|
from: "feature/ui",
|
||||||
|
remoteUrl: "git@gitlab.com:peter/public/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, "bash")
|
||||||
|
assert.Equal(t, args, []string{"-c", `open "https://gitlab.com/peter/public/calculator/merge_requests/new?merge_request[source_branch]=feature/ui"`})
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
test: func(url string, err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "https://gitlab.com/peter/public/calculator/merge_requests/new?merge_request[source_branch]=feature/ui", url)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on gitlab with specific target branch",
|
||||||
|
from: "feature/commit-ui",
|
||||||
|
to: "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, "bash")
|
||||||
|
assert.Equal(t, args, []string{"-c", `open "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: "Opens a link to new pull request on gitlab with specific target branch in nested groups",
|
||||||
|
from: "feature/commit-ui",
|
||||||
|
to: "epic/ui",
|
||||||
|
remoteUrl: "git@gitlab.com:peter/public/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, "bash")
|
||||||
|
assert.Equal(t, args, []string{"-c", `open "https://gitlab.com/peter/public/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/public/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",
|
||||||
|
from: "feature/divide-operation",
|
||||||
|
remoteUrl: "git@something.com:peter/calculator.git",
|
||||||
|
command: func(cmd string, args ...string) *exec.Cmd {
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
test: func(url string, err error) {
|
||||||
|
assert.Error(t, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range scenarios {
|
||||||
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
|
gitCommand := NewDummyGitCommand()
|
||||||
|
gitCommand.OSCommand.Command = s.command
|
||||||
|
gitCommand.OSCommand.Platform.OS = "darwin"
|
||||||
|
gitCommand.OSCommand.Platform.Shell = "bash"
|
||||||
|
gitCommand.OSCommand.Platform.ShellArg = "-c"
|
||||||
|
gitCommand.OSCommand.Config.GetUserConfig().OS.OpenLinkCommand = "open {{link}}"
|
||||||
|
gitCommand.OSCommand.Config.GetUserConfig().Services = map[string]string{
|
||||||
|
// valid configuration for a custom service URL
|
||||||
|
"git.work.com": "gitlab:code.work.com",
|
||||||
|
// invalid configurations for a custom service URL
|
||||||
|
"invalid.work.com": "noservice:invalid.work.com",
|
||||||
|
"noservice.work.com": "noservice.work.com",
|
||||||
|
}
|
||||||
|
gitCommand.getGitConfigValue = func(path string) (string, error) {
|
||||||
|
assert.Equal(t, path, "remote.origin.url")
|
||||||
|
return s.remoteUrl, nil
|
||||||
|
}
|
||||||
|
dummyPullRequest := NewPullRequest(gitCommand)
|
||||||
|
s.test(dummyPullRequest.Create(s.from, s.to))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,8 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/secureexec"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -42,245 +39,3 @@ func TestGetRepoInfoFromURL(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestCreatePullRequest is a function.
|
|
||||||
func TestCreatePullRequest(t *testing.T) {
|
|
||||||
type scenario struct {
|
|
||||||
testName string
|
|
||||||
from string
|
|
||||||
to string
|
|
||||||
remoteUrl string
|
|
||||||
command func(string, ...string) *exec.Cmd
|
|
||||||
test func(url string, err error)
|
|
||||||
}
|
|
||||||
|
|
||||||
scenarios := []scenario{
|
|
||||||
{
|
|
||||||
testName: "Opens a link to new pull request on bitbucket",
|
|
||||||
from: "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, "bash")
|
|
||||||
assert.Equal(t, args, []string{"-c", `open "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=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&t=1", url)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
testName: "Opens a link to new pull request on bitbucket with http remote url",
|
|
||||||
from: "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, "bash")
|
|
||||||
assert.Equal(t, args, []string{"-c", `open "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=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/events&t=1", url)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
testName: "Opens a link to new pull request on github",
|
|
||||||
from: "feature/sum-operation",
|
|
||||||
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, "bash")
|
|
||||||
assert.Equal(t, args, []string{"-c", `open "https://github.com/peter/calculator/compare/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/sum-operation?expand=1", url)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
testName: "Opens a link to new pull request on bitbucket with specific target branch",
|
|
||||||
from: "feature/profile-page/avatar",
|
|
||||||
to: "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, "bash")
|
|
||||||
assert.Equal(t, args, []string{"-c", `open "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: "feature/remote-events",
|
|
||||||
to: "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, "bash")
|
|
||||||
assert.Equal(t, args, []string{"-c", `open "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: "feature/sum-operation",
|
|
||||||
to: "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, "bash")
|
|
||||||
assert.Equal(t, args, []string{"-c", `open "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",
|
|
||||||
from: "feature/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, "bash")
|
|
||||||
assert.Equal(t, args, []string{"-c", `open "https://gitlab.com/peter/calculator/merge_requests/new?merge_request[source_branch]=feature/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/ui", url)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
testName: "Opens a link to new pull request on gitlab in nested groups",
|
|
||||||
from: "feature/ui",
|
|
||||||
remoteUrl: "git@gitlab.com:peter/public/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, "bash")
|
|
||||||
assert.Equal(t, args, []string{"-c", `open "https://gitlab.com/peter/public/calculator/merge_requests/new?merge_request[source_branch]=feature/ui"`})
|
|
||||||
return secureexec.Command("echo")
|
|
||||||
},
|
|
||||||
test: func(url string, err error) {
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, "https://gitlab.com/peter/public/calculator/merge_requests/new?merge_request[source_branch]=feature/ui", url)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
testName: "Opens a link to new pull request on gitlab with specific target branch",
|
|
||||||
from: "feature/commit-ui",
|
|
||||||
to: "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, "bash")
|
|
||||||
assert.Equal(t, args, []string{"-c", `open "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: "Opens a link to new pull request on gitlab with specific target branch in nested groups",
|
|
||||||
from: "feature/commit-ui",
|
|
||||||
to: "epic/ui",
|
|
||||||
remoteUrl: "git@gitlab.com:peter/public/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, "bash")
|
|
||||||
assert.Equal(t, args, []string{"-c", `open "https://gitlab.com/peter/public/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/public/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",
|
|
||||||
from: "feature/divide-operation",
|
|
||||||
remoteUrl: "git@something.com:peter/calculator.git",
|
|
||||||
command: func(cmd string, args ...string) *exec.Cmd {
|
|
||||||
return secureexec.Command("echo")
|
|
||||||
},
|
|
||||||
test: func(url string, err error) {
|
|
||||||
assert.Error(t, err)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, s := range scenarios {
|
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
|
||||||
gitCommand := NewDummyGitCommand()
|
|
||||||
gitCommand.OSCommand.Command = s.command
|
|
||||||
gitCommand.OSCommand.Config.GetUserConfig().OS.OpenLinkCommand = "open {{link}}"
|
|
||||||
gitCommand.OSCommand.Config.GetUserConfig().Services = map[string]string{
|
|
||||||
// valid configuration for a custom service URL
|
|
||||||
"git.work.com": "gitlab:code.work.com",
|
|
||||||
// invalid configurations for a custom service URL
|
|
||||||
"invalid.work.com": "noservice:invalid.work.com",
|
|
||||||
"noservice.work.com": "noservice.work.com",
|
|
||||||
}
|
|
||||||
gitCommand.getGitConfigValue = func(path string) (string, error) {
|
|
||||||
assert.Equal(t, path, "remote.origin.url")
|
|
||||||
return s.remoteUrl, nil
|
|
||||||
}
|
|
||||||
dummyPullRequest := NewPullRequest(gitCommand)
|
|
||||||
s.test(dummyPullRequest.Create(s.from, s.to))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
258
pkg/commands/pull_request_windows_test.go
Normal file
258
pkg/commands/pull_request_windows_test.go
Normal file
@ -0,0 +1,258 @@
|
|||||||
|
//go:build windows
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/secureexec"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestCreatePullRequestOnWindows is a function.
|
||||||
|
func TestCreatePullRequestOnWindows(t *testing.T) {
|
||||||
|
type scenario struct {
|
||||||
|
testName string
|
||||||
|
from string
|
||||||
|
to string
|
||||||
|
remoteUrl string
|
||||||
|
command func(string, ...string) *exec.Cmd
|
||||||
|
test func(url string, err error)
|
||||||
|
}
|
||||||
|
|
||||||
|
scenarios := []scenario{
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on bitbucket",
|
||||||
|
from: "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, "cmd")
|
||||||
|
assert.Equal(t, args, []string{"/c", "start", "", "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=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&t=1", url)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on bitbucket with http remote url",
|
||||||
|
from: "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, "cmd")
|
||||||
|
assert.Equal(t, args, []string{"/c", "start", "", "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=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/events&t=1", url)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on github",
|
||||||
|
from: "feature/sum-operation",
|
||||||
|
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, "cmd")
|
||||||
|
assert.Equal(t, args, []string{"/c", "start", "", "https://github.com/peter/calculator/compare/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/sum-operation?expand=1", url)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on bitbucket with specific target branch",
|
||||||
|
from: "feature/profile-page/avatar",
|
||||||
|
to: "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, "cmd")
|
||||||
|
assert.Equal(t, args, []string{"/c", "start", "", "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: "feature/remote-events",
|
||||||
|
to: "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, "cmd")
|
||||||
|
assert.Equal(t, args, []string{"/c", "start", "", "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: "feature/sum-operation",
|
||||||
|
to: "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, "cmd")
|
||||||
|
assert.Equal(t, args, []string{"/c", "start", "", "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",
|
||||||
|
from: "feature/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, "cmd")
|
||||||
|
assert.Equal(t, args, []string{"/c", "start", "", "https://gitlab.com/peter/calculator/merge_requests/new?merge_request[source_branch]=feature/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/ui", url)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on gitlab in nested groups",
|
||||||
|
from: "feature/ui",
|
||||||
|
remoteUrl: "git@gitlab.com:peter/public/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, "cmd")
|
||||||
|
assert.Equal(t, args, []string{"/c", "start", "", "https://gitlab.com/peter/public/calculator/merge_requests/new?merge_request[source_branch]=feature/ui"})
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
test: func(url string, err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "https://gitlab.com/peter/public/calculator/merge_requests/new?merge_request[source_branch]=feature/ui", url)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Opens a link to new pull request on gitlab with specific target branch",
|
||||||
|
from: "feature/commit-ui",
|
||||||
|
to: "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, "cmd")
|
||||||
|
assert.Equal(t, args, []string{"/c", "start", "", "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: "Opens a link to new pull request on gitlab with specific target branch in nested groups",
|
||||||
|
from: "feature/commit-ui",
|
||||||
|
to: "epic/ui",
|
||||||
|
remoteUrl: "git@gitlab.com:peter/public/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, "cmd")
|
||||||
|
assert.Equal(t, args, []string{"/c", "start", "", "https://gitlab.com/peter/public/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/public/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",
|
||||||
|
from: "feature/divide-operation",
|
||||||
|
remoteUrl: "git@something.com:peter/calculator.git",
|
||||||
|
command: func(cmd string, args ...string) *exec.Cmd {
|
||||||
|
return secureexec.Command("echo")
|
||||||
|
},
|
||||||
|
test: func(url string, err error) {
|
||||||
|
assert.Error(t, err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range scenarios {
|
||||||
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
|
gitCommand := NewDummyGitCommand()
|
||||||
|
gitCommand.OSCommand.Command = s.command
|
||||||
|
gitCommand.OSCommand.Platform.OS = "windows"
|
||||||
|
gitCommand.OSCommand.Platform.Shell = "cmd"
|
||||||
|
gitCommand.OSCommand.Platform.ShellArg = "/c"
|
||||||
|
gitCommand.OSCommand.Config.GetUserConfig().OS.OpenLinkCommand = `start "" {{link}}`
|
||||||
|
gitCommand.OSCommand.Config.GetUserConfig().Services = map[string]string{
|
||||||
|
// valid configuration for a custom service URL
|
||||||
|
"git.work.com": "gitlab:code.work.com",
|
||||||
|
// invalid configurations for a custom service URL
|
||||||
|
"invalid.work.com": "noservice:invalid.work.com",
|
||||||
|
"noservice.work.com": "noservice.work.com",
|
||||||
|
}
|
||||||
|
gitCommand.getGitConfigValue = func(path string) (string, error) {
|
||||||
|
assert.Equal(t, path, "remote.origin.url")
|
||||||
|
return s.remoteUrl, nil
|
||||||
|
}
|
||||||
|
dummyPullRequest := NewPullRequest(gitCommand)
|
||||||
|
s.test(dummyPullRequest.Create(s.from, s.to))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user