summaryrefslogtreecommitdiff
path: root/cmd/rr
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2023-02-16 16:33:37 +0100
committerValery Piashchynski <[email protected]>2023-02-16 16:33:37 +0100
commit488ec54b9b6dda5c4b77163a91599d35ae52bbfa (patch)
tree06294d92a934ee304c175481c393dbdf6b758a7a /cmd/rr
parent1d53ec90b91046727cbbf5ec012febc07d88b28b (diff)
fix: command tests
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'cmd/rr')
-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")