package commands
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"testing"
"time"
"github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/jesseduffield/lazygit/pkg/test"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
gogit "gopkg.in/src-d/go-git.v4"
)
type fileInfoMock struct {
name string
size int64
fileMode os.FileMode
fileModTime time.Time
isDir bool
sys interface{}
}
func (f fileInfoMock) Name() string {
return f.name
}
func (f fileInfoMock) Size() int64 {
return f.size
}
func (f fileInfoMock) Mode() os.FileMode {
return f.fileMode
}
func (f fileInfoMock) ModTime() time.Time {
return f.fileModTime
}
func (f fileInfoMock) IsDir() bool {
return f.isDir
}
func (f fileInfoMock) Sys() interface{} {
return f.sys
}
func newDummyLog() *logrus.Entry {
log := logrus.New()
log.Out = ioutil.Discard
return log.WithField("test", "test")
}
func newDummyGitCommand() *GitCommand {
return &GitCommand{
Log: newDummyLog(),
OSCommand: newDummyOSCommand(),
Tr: i18n.NewLocalizer(newDummyLog()),
getGlobalGitConfig: func(string) (string, error) { return "", nil },
getLocalGitConfig: func(string) (string, error) { return "", nil },
}
}
func TestVerifyInGitRepo(t *testing.T) {
type scenario struct {
testName string
runCmd func(string) error
test func(error)
}
scenarios := []scenario{
{
"Valid git repository",
func(string) error {
return nil
},
func(err error) {
assert.NoError(t, err)
},
},
{
"Not a valid git repository",
func(string) error {
return fmt.Errorf("fatal: Not a git repository (or any of the parent directories): .git")
},
func(err error) {
assert.Error(t, err)
assert.Regexp(t, "fatal: .ot a git repository \\(or any of the parent directories\\): \\.git", err.Error())
},
},
}
for _, s := range scenarios {