diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-03-02 13:08:09 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-03-02 13:39:09 +1100 |
commit | 4de31da4bee9c622d4c6b7152e4d918b79cb4a94 (patch) | |
tree | bd64b31772230132dcbeac5be7787c612ee0e53c /pkg/commands/os_test.go | |
parent | 23c51ba70841ef779e7fcef9fd2a5c717835e168 (diff) |
fix up tests
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
Diffstat (limited to 'pkg/commands/os_test.go')
-rw-r--r-- | pkg/commands/os_test.go | 41 |
1 files changed, 10 insertions, 31 deletions
diff --git a/pkg/commands/os_test.go b/pkg/commands/os_test.go index a08c4b57d..2141b0e1e 100644 --- a/pkg/commands/os_test.go +++ b/pkg/commands/os_test.go @@ -6,30 +6,9 @@ import ( "os/exec" "testing" - "github.com/jesseduffield/lazygit/pkg/config" - "github.com/spf13/viper" "github.com/stretchr/testify/assert" - yaml "gopkg.in/yaml.v2" ) -func newDummyOSCommand() *OSCommand { - return NewOSCommand(newDummyLog(), newDummyAppConfig()) -} - -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 -} - // TestOSCommandRunCommandWithOutput is a function. func TestOSCommandRunCommandWithOutput(t *testing.T) { type scenario struct { @@ -54,7 +33,7 @@ func TestOSCommandRunCommandWithOutput(t *testing.T) { } for _, s := range scenarios { - s.test(newDummyOSCommand().RunCommandWithOutput(s.command)) + s.test(NewDummyOSCommand().RunCommandWithOutput(s.command)) } } @@ -75,7 +54,7 @@ func TestOSCommandRunCommand(t *testing.T) { } for _, s := range scenarios { - s.test(newDummyOSCommand().RunCommand(s.command)) + s.test(NewDummyOSCommand().RunCommand(s.command)) } } @@ -122,7 +101,7 @@ func TestOSCommandOpenFile(t *testing.T) { } for _, s := range scenarios { - OSCmd := newDummyOSCommand() + OSCmd := NewDummyOSCommand() OSCmd.command = s.command OSCmd.Config.GetUserConfig().Set("os.openCommand", "open {{filename}}") @@ -251,7 +230,7 @@ func TestOSCommandEditFile(t *testing.T) { } for _, s := range scenarios { - OSCmd := newDummyOSCommand() + OSCmd := NewDummyOSCommand() OSCmd.command = s.command OSCmd.getGlobalGitConfig = s.getGlobalGitConfig OSCmd.getenv = s.getenv @@ -262,7 +241,7 @@ func TestOSCommandEditFile(t *testing.T) { // TestOSCommandQuote is a function. func TestOSCommandQuote(t *testing.T) { - osCommand := newDummyOSCommand() + osCommand := NewDummyOSCommand() actual := osCommand.Quote("hello `test`") @@ -273,7 +252,7 @@ func TestOSCommandQuote(t *testing.T) { // TestOSCommandQuoteSingleQuote tests the quote function with ' quotes explicitly for Linux func TestOSCommandQuoteSingleQuote(t *testing.T) { - osCommand := newDummyOSCommand() + osCommand := NewDummyOSCommand() osCommand.Platform.os = "linux" @@ -286,7 +265,7 @@ func TestOSCommandQuoteSingleQuote(t *testing.T) { // TestOSCommandQuoteDoubleQuote tests the quote function with " quotes explicitly for Linux func TestOSCommandQuoteDoubleQuote(t *testing.T) { - osCommand := newDummyOSCommand() + osCommand := NewDummyOSCommand() osCommand.Platform.os = "linux" @@ -299,7 +278,7 @@ func TestOSCommandQuoteDoubleQuote(t *testing.T) { // TestOSCommandUnquote is a function. func TestOSCommandUnquote(t *testing.T) { - osCommand := newDummyOSCommand() + osCommand := NewDummyOSCommand() actual := osCommand.Unquote(`hello "test"`) @@ -361,7 +340,7 @@ func TestOSCommandFileType(t *testing.T) { for _, s := range scenarios { s.setup() - s.test(newDummyOSCommand().FileType(s.path)) + s.test(NewDummyOSCommand().FileType(s.path)) _ = os.RemoveAll(s.path) } } @@ -392,7 +371,7 @@ func TestOSCommandCreateTempFile(t *testing.T) { for _, s := range scenarios { t.Run(s.testName, func(t *testing.T) { - s.test(newDummyOSCommand().CreateTempFile(s.filename, s.content)) + s.test(NewDummyOSCommand().CreateTempFile(s.filename, s.content)) }) } } |