2022-09-10 12:09:19 +03:00
|
|
|
package execenv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2022-12-21 23:54:36 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2022-09-10 12:09:19 +03:00
|
|
|
"github.com/MichaelMure/git-bug/cache"
|
|
|
|
"github.com/MichaelMure/git-bug/repository"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TestOut struct {
|
|
|
|
*bytes.Buffer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (te *TestOut) Printf(format string, a ...interface{}) {
|
|
|
|
_, _ = fmt.Fprintf(te.Buffer, format, a...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (te *TestOut) Print(a ...interface{}) {
|
|
|
|
_, _ = fmt.Fprint(te.Buffer, a...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (te *TestOut) Println(a ...interface{}) {
|
|
|
|
_, _ = fmt.Fprintln(te.Buffer, a...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTestEnv(t *testing.T) *Env {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
repo := repository.CreateGoGitTestRepo(t, false)
|
|
|
|
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
|
2022-12-23 01:19:31 +03:00
|
|
|
backend, err := cache.NewRepoCacheNoEvents(repo)
|
2022-09-10 12:09:19 +03:00
|
|
|
require.NoError(t, err)
|
2022-12-21 23:54:36 +03:00
|
|
|
|
2022-09-10 12:09:19 +03:00
|
|
|
t.Cleanup(func() {
|
|
|
|
backend.Close()
|
|
|
|
})
|
|
|
|
|
|
|
|
return &Env{
|
|
|
|
Repo: repo,
|
|
|
|
Backend: backend,
|
|
|
|
Out: &TestOut{buf},
|
|
|
|
Err: &TestOut{buf},
|
|
|
|
}
|
|
|
|
}
|