mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 21:05:48 +02:00
fix tests
This commit is contained in:
parent
e89bf5d06b
commit
cb0bdd89c0
2 changed files with 13 additions and 6 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/jesseduffield/lazygit/pkg/i18n"
|
"github.com/jesseduffield/lazygit/pkg/i18n"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
appconfig "github.com/jesseduffield/lazygit/pkg/config"
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,6 +20,11 @@ func NewDummyOSCommand() *OSCommand {
|
||||||
|
|
||||||
// NewDummyAppConfig creates a new dummy AppConfig for testing
|
// NewDummyAppConfig creates a new dummy AppConfig for testing
|
||||||
func NewDummyAppConfig() *config.AppConfig {
|
func NewDummyAppConfig() *config.AppConfig {
|
||||||
|
userConfig := viper.New()
|
||||||
|
userConfig.SetConfigType("yaml")
|
||||||
|
if err := appconfig.LoadDefaults(userConfig, appconfig.GetDefaultConfig()); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
appConfig := &config.AppConfig{
|
appConfig := &config.AppConfig{
|
||||||
Name: "lazygit",
|
Name: "lazygit",
|
||||||
Version: "unversioned",
|
Version: "unversioned",
|
||||||
|
@ -26,7 +32,7 @@ func NewDummyAppConfig() *config.AppConfig {
|
||||||
BuildDate: "",
|
BuildDate: "",
|
||||||
Debug: false,
|
Debug: false,
|
||||||
BuildSource: "",
|
BuildSource: "",
|
||||||
UserConfig: viper.New(),
|
UserConfig: userConfig,
|
||||||
}
|
}
|
||||||
_ = yaml.Unmarshal([]byte{}, appConfig.AppState)
|
_ = yaml.Unmarshal([]byte{}, appConfig.AppState)
|
||||||
return appConfig
|
return appConfig
|
||||||
|
|
|
@ -1384,13 +1384,14 @@ func TestGitCommandCheckout(t *testing.T) {
|
||||||
// TestGitCommandGetBranchGraph is a function.
|
// TestGitCommandGetBranchGraph is a function.
|
||||||
func TestGitCommandGetBranchGraph(t *testing.T) {
|
func TestGitCommandGetBranchGraph(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommand()
|
gitCmd := NewDummyGitCommand()
|
||||||
|
gitCmd.getLocalGitConfig = func(string) (string, error) {
|
||||||
|
return "git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --", nil
|
||||||
|
}
|
||||||
gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.Cmd {
|
gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.Cmd {
|
||||||
assert.EqualValues(t, "git", cmd)
|
assert.EqualValues(t, "git", cmd)
|
||||||
assert.EqualValues(t, []string{"log", "--graph", "--color=always", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium", "test", "--"}, args)
|
assert.EqualValues(t, []string{"log", "--graph", "--color=always", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium", "test", "--"}, args)
|
||||||
|
|
||||||
return exec.Command("echo")
|
return exec.Command("echo")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := gitCmd.GetBranchGraph("test")
|
_, err := gitCmd.GetBranchGraph("test")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
@ -1410,7 +1411,7 @@ func TestGitCommandDiff(t *testing.T) {
|
||||||
"Default case",
|
"Default case",
|
||||||
func(cmd string, args ...string) *exec.Cmd {
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
assert.EqualValues(t, "git", cmd)
|
assert.EqualValues(t, "git", cmd)
|
||||||
assert.EqualValues(t, []string{"diff", "--color=", "--", "test.txt"}, args)
|
assert.EqualValues(t, []string{"diff", "--color=always", "--", "test.txt"}, args)
|
||||||
|
|
||||||
return exec.Command("echo")
|
return exec.Command("echo")
|
||||||
},
|
},
|
||||||
|
@ -1426,7 +1427,7 @@ func TestGitCommandDiff(t *testing.T) {
|
||||||
"cached",
|
"cached",
|
||||||
func(cmd string, args ...string) *exec.Cmd {
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
assert.EqualValues(t, "git", cmd)
|
assert.EqualValues(t, "git", cmd)
|
||||||
assert.EqualValues(t, []string{"diff", "--color=", "--cached", "--", "test.txt"}, args)
|
assert.EqualValues(t, []string{"diff", "--color=always", "--cached", "--", "test.txt"}, args)
|
||||||
|
|
||||||
return exec.Command("echo")
|
return exec.Command("echo")
|
||||||
},
|
},
|
||||||
|
@ -1458,7 +1459,7 @@ func TestGitCommandDiff(t *testing.T) {
|
||||||
"File not tracked and file has no staged changes",
|
"File not tracked and file has no staged changes",
|
||||||
func(cmd string, args ...string) *exec.Cmd {
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
assert.EqualValues(t, "git", cmd)
|
assert.EqualValues(t, "git", cmd)
|
||||||
assert.EqualValues(t, []string{"diff", "--color=", "--no-index", "/dev/null", "test.txt"}, args)
|
assert.EqualValues(t, []string{"diff", "--color=always", "--no-index", "/dev/null", "test.txt"}, args)
|
||||||
|
|
||||||
return exec.Command("echo")
|
return exec.Command("echo")
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue