aboutsummaryrefslogtreecommitdiffstats
path: root/commands/execenv/env_testing.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/execenv/env_testing.go')
-rw-r--r--commands/execenv/env_testing.go50
1 files changed, 46 insertions, 4 deletions
diff --git a/commands/execenv/env_testing.go b/commands/execenv/env_testing.go
index 34eafc9c..15d7b646 100644
--- a/commands/execenv/env_testing.go
+++ b/commands/execenv/env_testing.go
@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
+ "io"
"testing"
"github.com/stretchr/testify/require"
@@ -12,8 +13,26 @@ import (
"github.com/MichaelMure/git-bug/repository"
)
+var _ In = &TestIn{}
+
+type TestIn struct {
+ *bytes.Buffer
+ forceIsTerminal bool
+}
+
+func (t *TestIn) IsTerminal() bool {
+ return t.forceIsTerminal
+}
+
+func (t *TestIn) ForceIsTerminal(value bool) {
+ t.forceIsTerminal = value
+}
+
+var _ Out = &TestOut{}
+
type TestOut struct {
*bytes.Buffer
+ forceIsTerminal bool
}
func (te *TestOut) Printf(format string, a ...interface{}) {
@@ -37,12 +56,34 @@ func (te *TestOut) PrintJSON(v interface{}) error {
return nil
}
+func (te *TestOut) IsTerminal() bool {
+ return te.forceIsTerminal
+}
+
+func (te *TestOut) Width() int {
+ return 80
+}
+
+func (te *TestOut) Raw() io.Writer {
+ return te.Buffer
+}
+
+func (te *TestOut) ForceIsTerminal(value bool) {
+ te.forceIsTerminal = value
+}
+
func NewTestEnv(t *testing.T) *Env {
t.Helper()
+ return newTestEnv(t, false)
+}
- repo := repository.CreateGoGitTestRepo(t, false)
+func NewTestEnvTerminal(t *testing.T) *Env {
+ t.Helper()
+ return newTestEnv(t, true)
+}
- buf := new(bytes.Buffer)
+func newTestEnv(t *testing.T, isTerminal bool) *Env {
+ repo := repository.CreateGoGitTestRepo(t, false)
backend, err := cache.NewRepoCacheNoEvents(repo)
require.NoError(t, err)
@@ -54,7 +95,8 @@ func NewTestEnv(t *testing.T) *Env {
return &Env{
Repo: repo,
Backend: backend,
- Out: &TestOut{buf},
- Err: &TestOut{buf},
+ In: &TestIn{Buffer: &bytes.Buffer{}, forceIsTerminal: isTerminal},
+ Out: &TestOut{Buffer: &bytes.Buffer{}, forceIsTerminal: isTerminal},
+ Err: &TestOut{Buffer: &bytes.Buffer{}, forceIsTerminal: isTerminal},
}
}