aboutsummaryrefslogtreecommitdiffstats
path: root/commands/execenv/env_test.go
diff options
context:
space:
mode:
authorSteve Moyer <smoyer1@selesy.com>2023-01-16 10:57:51 -0500
committerSteve Moyer <smoyer1@selesy.com>2023-01-16 10:57:51 -0500
commit146037733472eb74429d6c053ccbb8087fe70bca (patch)
tree6f271663b62f4763460e2437fdd44985b711f838 /commands/execenv/env_test.go
parent2a78fd9c94960d86264e39d37e5a3e25b0a8358d (diff)
downloadgit-bug-146037733472eb74429d6c053ccbb8087fe70bca.tar.gz
feat: detect os.Stdin/os.Stdout mode
Diffstat (limited to 'commands/execenv/env_test.go')
-rw-r--r--commands/execenv/env_test.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/commands/execenv/env_test.go b/commands/execenv/env_test.go
new file mode 100644
index 00000000..11ebdca1
--- /dev/null
+++ b/commands/execenv/env_test.go
@@ -0,0 +1,61 @@
+package execenv
+
+import (
+ "os"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestGetIOMode(t *testing.T) {
+ r, w, err := os.Pipe()
+ require.NoError(t, err)
+
+ testcases := []struct {
+ name string
+ in *os.File
+ out *os.File
+ expInMode IOMode
+ expOutMode IOMode
+ }{
+ {
+ name: "neither redirected",
+ in: os.Stdin,
+ out: os.Stdout,
+ expInMode: TerminalIOMode,
+ expOutMode: TerminalIOMode,
+ },
+ {
+ name: "in redirected",
+ in: w,
+ out: os.Stdout,
+ expInMode: TerminalIOMode,
+ expOutMode: TerminalIOMode,
+ },
+ {
+ name: "out redirected",
+ in: os.Stdin,
+ out: r,
+ expInMode: TerminalIOMode,
+ expOutMode: TerminalIOMode,
+ },
+ {
+ name: "both redirected",
+ in: w,
+ out: r,
+ expInMode: PipedOrRedirectedIOMode,
+ expOutMode: PipedOrRedirectedIOMode,
+ },
+ }
+
+ for i := range testcases {
+ testcase := testcases[i]
+
+ t.Run(testcase.name, func(t *testing.T) {
+ t.Parallel()
+
+ env := NewEnv()
+ require.NotNil(t, env)
+ })
+ }
+}