various changes to improve integration tests

This commit is contained in:
Jesse Duffield 2022-09-09 21:11:05 -07:00
parent 7b757d1cfe
commit 7af7af27c6
103 changed files with 2883 additions and 1525 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/jesseduffield/lazygit/pkg/secureexec"
"github.com/mgutz/str"
@ -12,16 +13,20 @@ import (
// this is for running shell commands, mostly for the sake of setting up the repo
// but you can also run the commands from within lazygit to emulate things happening
// in the background.
type Shell struct{}
type Shell struct {
// working directory the shell is invoked in
dir string
}
func NewShell() *Shell {
return &Shell{}
func NewShell(dir string) *Shell {
return &Shell{dir: dir}
}
func (s *Shell) RunCommand(cmdStr string) *Shell {
args := str.ToArgv(cmdStr)
cmd := secureexec.Command(args[0], args[1:]...)
cmd.Env = os.Environ()
cmd.Dir = s.dir
output, err := cmd.CombinedOutput()
if err != nil {
@ -32,18 +37,20 @@ func (s *Shell) RunCommand(cmdStr string) *Shell {
}
func (s *Shell) CreateFile(path string, content string) *Shell {
err := ioutil.WriteFile(path, []byte(content), 0o644)
fullPath := filepath.Join(s.dir, path)
err := ioutil.WriteFile(fullPath, []byte(content), 0o644)
if err != nil {
panic(fmt.Sprintf("error creating file: %s\n%s", path, err))
panic(fmt.Sprintf("error creating file: %s\n%s", fullPath, err))
}
return s
}
func (s *Shell) UpdateFile(path string, content string) *Shell {
err := ioutil.WriteFile(path, []byte(content), 0o644)
fullPath := filepath.Join(s.dir, path)
err := ioutil.WriteFile(fullPath, []byte(content), 0o644)
if err != nil {
panic(fmt.Sprintf("error updating file: %s\n%s", path, err))
panic(fmt.Sprintf("error updating file: %s\n%s", fullPath, err))
}
return s