mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-11-26 09:00:57 +02:00
4de31da4be
This fixes up some git and oscommand tests, and pulls some tests into commit_list_builder_test.go I've also made the NewDummyBlah functions public so that I didn't need to duplicate them across packages I've also given OSCommand a SetCommand() method for setting the command on the struct I've also created a file utils.go in the test package for creating convient 'CommandSwapper's, which basically enable you to assert a sequence of commands on the command line, and swap each one out for a different one to actually be executed
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package commands
|
|
|
|
import (
|
|
"io/ioutil"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/config"
|
|
"github.com/jesseduffield/lazygit/pkg/i18n"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/spf13/viper"
|
|
yaml "gopkg.in/yaml.v2"
|
|
)
|
|
|
|
// This file exports dummy constructors for use by tests in other packages
|
|
|
|
// NewDummyOSCommand creates a new dummy OSCommand for testing
|
|
func NewDummyOSCommand() *OSCommand {
|
|
return NewOSCommand(NewDummyLog(), NewDummyAppConfig())
|
|
}
|
|
|
|
// NewDummyAppConfig creates a new dummy AppConfig for testing
|
|
func NewDummyAppConfig() *config.AppConfig {
|
|
appConfig := &config.AppConfig{
|
|
Name: "lazygit",
|
|
Version: "unversioned",
|
|
Commit: "",
|
|
BuildDate: "",
|
|
Debug: false,
|
|
BuildSource: "",
|
|
UserConfig: viper.New(),
|
|
}
|
|
_ = yaml.Unmarshal([]byte{}, appConfig.AppState)
|
|
return appConfig
|
|
}
|
|
|
|
// NewDummyLog creates a new dummy Log for testing
|
|
func NewDummyLog() *logrus.Entry {
|
|
log := logrus.New()
|
|
log.Out = ioutil.Discard
|
|
return log.WithField("test", "test")
|
|
}
|
|
|
|
// NewDummyGitCommand creates a new dummy GitCommand for testing
|
|
func NewDummyGitCommand() *GitCommand {
|
|
return NewDummyGitCommandWithOSCommand(NewDummyOSCommand())
|
|
}
|
|
|
|
// NewDummyGitCommandWithOSCommand creates a new dummy GitCommand for testing
|
|
func NewDummyGitCommandWithOSCommand(osCommand *OSCommand) *GitCommand {
|
|
return &GitCommand{
|
|
Log: NewDummyLog(),
|
|
OSCommand: osCommand,
|
|
Tr: i18n.NewLocalizer(NewDummyLog()),
|
|
Config: NewDummyAppConfig(),
|
|
getGlobalGitConfig: func(string) (string, error) { return "", nil },
|
|
getLocalGitConfig: func(string) (string, error) { return "", nil },
|
|
removeFile: func(string) error { return nil },
|
|
}
|
|
}
|