summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2023-02-16 13:49:42 +0100
committerValery Piashchynski <[email protected]>2023-02-16 13:49:42 +0100
commita5bb90d841c7c9e34f57db77498550a9e80395ab (patch)
tree7e402926ca0032e1dcf727f6177ce75e57fbefe5
parent6745e9ecedb6a788341cb3554e3c25badc9fc452 (diff)
fix tests stdout
Signed-off-by: Valery Piashchynski <[email protected]>
-rw-r--r--cmd/rr/command_test.go26
1 files changed, 12 insertions, 14 deletions
diff --git a/cmd/rr/command_test.go b/cmd/rr/command_test.go
index 84eef9d7..9b3e5f6a 100644
--- a/cmd/rr/command_test.go
+++ b/cmd/rr/command_test.go
@@ -5,24 +5,24 @@ import (
"io"
"os"
"testing"
+ "time"
"github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
)
func Test_Main(t *testing.T) {
os.Args = []string{"rr", "--help"}
exitFn = func(code int) { assert.Equal(t, 0, code) }
- r, w, err := os.Pipe()
- require.NoError(t, err)
+ r, w, _ := os.Pipe()
os.Stdout = w
main()
_ = w.Close()
buf := new(bytes.Buffer)
- _, err = io.Copy(buf, r)
- require.NoError(t, err)
+
+ _ = r.SetReadDeadline(time.Now().Add(time.Second))
+ _, _ = io.Copy(buf, r)
assert.Contains(t, buf.String(), "Usage:")
assert.Contains(t, buf.String(), "Available Commands:")
@@ -33,15 +33,13 @@ func Test_MainWithoutCommands(t *testing.T) {
os.Args = []string{"rr"}
exitFn = func(code int) { assert.Equal(t, 0, code) }
- r, w, err := os.Pipe()
- require.NoError(t, err)
+ r, w, _ := os.Pipe()
os.Stdout = w
main()
- _ = w.Close()
buf := new(bytes.Buffer)
- _, err = io.Copy(buf, r)
- require.NoError(t, err)
+ _ = r.SetReadDeadline(time.Now().Add(time.Second))
+ _, _ = io.Copy(buf, r)
assert.Contains(t, buf.String(), "Usage:")
assert.Contains(t, buf.String(), "Available Commands:")
@@ -52,15 +50,15 @@ func Test_MainUnknownSubcommand(t *testing.T) {
os.Args = []string{"", "foobar"}
exitFn = func(code int) { assert.Equal(t, 1, code) }
- r, w, err := os.Pipe()
- require.NoError(t, err)
+ r, w, _ := os.Pipe()
os.Stderr = w
main()
_ = w.Close()
buf := new(bytes.Buffer)
- _, err = io.Copy(buf, r)
- require.NoError(t, err)
+
+ _ = r.SetReadDeadline(time.Now().Add(time.Second))
+ _, _ = io.Copy(buf, r)
assert.Contains(t, buf.String(), "unknown command")
assert.Contains(t, buf.String(), "foobar")