github.hscsec.cn/jesseduffield/lazygit@v0.8.1/pkg/commands/dummies.go (about) 1 package commands 2 3 import ( 4 "io/ioutil" 5 6 "github.com/jesseduffield/lazygit/pkg/config" 7 "github.com/jesseduffield/lazygit/pkg/i18n" 8 "github.com/sirupsen/logrus" 9 "github.com/spf13/viper" 10 yaml "gopkg.in/yaml.v2" 11 ) 12 13 // This file exports dummy constructors for use by tests in other packages 14 15 // NewDummyOSCommand creates a new dummy OSCommand for testing 16 func NewDummyOSCommand() *OSCommand { 17 return NewOSCommand(NewDummyLog(), NewDummyAppConfig()) 18 } 19 20 // NewDummyAppConfig creates a new dummy AppConfig for testing 21 func NewDummyAppConfig() *config.AppConfig { 22 appConfig := &config.AppConfig{ 23 Name: "lazygit", 24 Version: "unversioned", 25 Commit: "", 26 BuildDate: "", 27 Debug: false, 28 BuildSource: "", 29 UserConfig: viper.New(), 30 } 31 _ = yaml.Unmarshal([]byte{}, appConfig.AppState) 32 return appConfig 33 } 34 35 // NewDummyLog creates a new dummy Log for testing 36 func NewDummyLog() *logrus.Entry { 37 log := logrus.New() 38 log.Out = ioutil.Discard 39 return log.WithField("test", "test") 40 } 41 42 // NewDummyGitCommand creates a new dummy GitCommand for testing 43 func NewDummyGitCommand() *GitCommand { 44 return NewDummyGitCommandWithOSCommand(NewDummyOSCommand()) 45 } 46 47 // NewDummyGitCommandWithOSCommand creates a new dummy GitCommand for testing 48 func NewDummyGitCommandWithOSCommand(osCommand *OSCommand) *GitCommand { 49 return &GitCommand{ 50 Log: NewDummyLog(), 51 OSCommand: osCommand, 52 Tr: i18n.NewLocalizer(NewDummyLog()), 53 Config: NewDummyAppConfig(), 54 getGlobalGitConfig: func(string) (string, error) { return "", nil }, 55 getLocalGitConfig: func(string) (string, error) { return "", nil }, 56 removeFile: func(string) error { return nil }, 57 } 58 }