1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-11 11:42:12 +02:00

fix tests

This commit is contained in:
Jasper Mendiola 2020-07-10 16:42:55 +08:00 committed by Jesse Duffield
parent e89bf5d06b
commit cb0bdd89c0
2 changed files with 13 additions and 6 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
appconfig "github.com/jesseduffield/lazygit/pkg/config"
yaml "gopkg.in/yaml.v2"
)
@ -19,6 +20,11 @@ func NewDummyOSCommand() *OSCommand {
// NewDummyAppConfig creates a new dummy AppConfig for testing
func NewDummyAppConfig() *config.AppConfig {
userConfig := viper.New()
userConfig.SetConfigType("yaml")
if err := appconfig.LoadDefaults(userConfig, appconfig.GetDefaultConfig()); err != nil {
panic(err)
}
appConfig := &config.AppConfig{
Name: "lazygit",
Version: "unversioned",
@ -26,7 +32,7 @@ func NewDummyAppConfig() *config.AppConfig {
BuildDate: "",
Debug: false,
BuildSource: "",
UserConfig: viper.New(),
UserConfig: userConfig,
}
_ = yaml.Unmarshal([]byte{}, appConfig.AppState)
return appConfig

View File

@ -1384,13 +1384,14 @@ func TestGitCommandCheckout(t *testing.T) {
// TestGitCommandGetBranchGraph is a function.
func TestGitCommandGetBranchGraph(t *testing.T) {
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 {
assert.EqualValues(t, "git", cmd)
assert.EqualValues(t, []string{"log", "--graph", "--color=always", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium", "test", "--"}, args)
return exec.Command("echo")
}
_, err := gitCmd.GetBranchGraph("test")
assert.NoError(t, err)
}
@ -1410,7 +1411,7 @@ func TestGitCommandDiff(t *testing.T) {
"Default case",
func(cmd string, args ...string) *exec.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")
},
@ -1426,7 +1427,7 @@ func TestGitCommandDiff(t *testing.T) {
"cached",
func(cmd string, args ...string) *exec.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")
},
@ -1458,7 +1459,7 @@ func TestGitCommandDiff(t *testing.T) {
"File not tracked and file has no staged changes",
func(cmd string, args ...string) *exec.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")
},