Skip to content

Commit fd39393

Browse files
committed
Fixing tests in windows
1 parent 0fc4282 commit fd39393

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

cmd/root_test.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package cmd
22

33
import (
44
"bytes"
5+
"io"
6+
"os"
7+
"strings"
58
"testing"
69

710
"github.com/spf13/cobra"
@@ -60,18 +63,30 @@ To get started, run 'glean --help'.`,
6063
}
6164

6265
func TestExecute(t *testing.T) {
63-
// Save original stdout
64-
oldOut := rootCmd.OutOrStdout()
66+
// Redirect stdout to capture output
67+
old := os.Stdout
68+
r, w, _ := os.Pipe()
69+
os.Stdout = w
70+
71+
// Reset stdout after test
6572
defer func() {
66-
rootCmd.SetOut(oldOut)
73+
os.Stdout = old
6774
}()
6875

69-
// Create a buffer to capture output
70-
b := bytes.NewBufferString("")
71-
rootCmd.SetOut(b)
76+
// Execute with help flag
77+
os.Args = []string{"glean", "--help"}
78+
if err := Execute(); err != nil {
79+
t.Errorf("Execute() error = %v", err)
80+
}
81+
82+
// Close writer and read output
83+
w.Close()
84+
var buf bytes.Buffer
85+
io.Copy(&buf, r)
86+
output := buf.String()
7287

73-
// Execute with no args should show help
74-
err := Execute()
75-
assert.NoError(t, err)
76-
assert.Contains(t, b.String(), "Work seamlessly with Glean from your command line")
88+
// Check output contains expected text
89+
if !strings.Contains(output, "Work seamlessly with Glean from your command line") {
90+
t.Errorf("Expected help text not found in output")
91+
}
7792
}

0 commit comments

Comments
 (0)