1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

fix tests

This commit is contained in:
Jesse Duffield
2022-01-08 13:22:29 +11:00
parent c6b57d9b57
commit 3621854dc7
16 changed files with 373 additions and 149 deletions

View File

@ -1,6 +1,7 @@
package oscommands
import (
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@ -11,6 +12,34 @@ func NewDummyOSCommand() *OSCommand {
return osCmd
}
type OSCommandDeps struct {
Common *common.Common
Platform *Platform
GetenvFn func(string) string
RemoveFileFn func(string) error
Cmd *CmdObjBuilder
}
func NewDummyOSCommandWithDeps(deps OSCommandDeps) *OSCommand {
common := deps.Common
if common == nil {
common = utils.NewDummyCommon()
}
platform := deps.Platform
if platform == nil {
platform = dummyPlatform
}
return &OSCommand{
Common: common,
Platform: platform,
getenvFn: deps.GetenvFn,
removeFileFn: deps.RemoveFileFn,
guiIO: NewNullGuiIO(utils.NewDummyLog()),
}
}
func NewDummyCmdObjBuilder(runner ICmdObjRunner) *CmdObjBuilder {
return &CmdObjBuilder{
runner: runner,

View File

@ -20,10 +20,10 @@ import (
type OSCommand struct {
*common.Common
Platform *Platform
GetenvFn func(string) string
getenvFn func(string) string
guiIO *guiIO
removeFile func(string) error
removeFileFn func(string) error
Cmd *CmdObjBuilder
}
@ -40,11 +40,11 @@ type Platform struct {
// NewOSCommand os command runner
func NewOSCommand(common *common.Common, platform *Platform, guiIO *guiIO) *OSCommand {
c := &OSCommand{
Common: common,
Platform: platform,
GetenvFn: os.Getenv,
removeFile: os.RemoveAll,
guiIO: guiIO,
Common: common,
Platform: platform,
getenvFn: os.Getenv,
removeFileFn: os.RemoveAll,
guiIO: guiIO,
}
runner := &cmdObjRunner{log: common.Log, guiIO: guiIO}
@ -59,11 +59,6 @@ func (c *OSCommand) LogCommand(cmdStr string, commandLine bool) {
c.guiIO.logCommandFn(cmdStr, commandLine)
}
// To be used for testing only
func (c *OSCommand) SetRemoveFile(f func(string) error) {
c.removeFile = f
}
// FileType tells us if the file is a file, directory or other
func FileType(path string) string {
fileInfo, err := os.Stat(path)
@ -253,11 +248,11 @@ func (c *OSCommand) CopyToClipboard(str string) error {
func (c *OSCommand) RemoveFile(path string) error {
c.LogCommand(fmt.Sprintf("Deleting path '%s'", path), false)
return c.removeFile(path)
return c.removeFileFn(path)
}
func (c *OSCommand) Getenv(key string) string {
return c.GetenvFn(key)
return c.getenvFn(key)
}
func GetTempDir() string {