forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ioutil_test.go
48 lines (36 loc) · 1.14 KB
/
ioutil_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package testutil_test
import (
"io/ioutil"
"testing"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/testutil"
)
func TestApplyMockIO(t *testing.T) {
cmd := &cobra.Command{}
oldStdin := cmd.InOrStdin()
oldStdout := cmd.OutOrStdout()
oldStderr := cmd.ErrOrStderr()
testutil.ApplyMockIO(cmd)
require.NotEqual(t, cmd.InOrStdin(), oldStdin)
require.NotEqual(t, cmd.OutOrStdout(), oldStdout)
require.NotEqual(t, cmd.ErrOrStderr(), oldStderr)
require.Equal(t, cmd.ErrOrStderr(), cmd.OutOrStdout())
}
func TestWriteToNewTempFile(t *testing.T) {
tempfile, cleanup := testutil.WriteToNewTempFile(t, "test string")
tempfile.Close()
bs, err := ioutil.ReadFile(tempfile.Name())
require.NoError(t, err)
require.Equal(t, "test string", string(bs))
cleanup()
require.NoFileExists(t, tempfile.Name())
}
func TestApplyMockIODiscardOutErr(t *testing.T) {
cmd := &cobra.Command{}
oldStdin := cmd.InOrStdin()
testutil.ApplyMockIODiscardOutErr(cmd)
require.NotEqual(t, cmd.InOrStdin(), oldStdin)
require.Equal(t, cmd.OutOrStdout(), ioutil.Discard)
require.Equal(t, cmd.ErrOrStderr(), ioutil.Discard)
}