50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
|
package helpers
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/require"
|
||
|
|
||
|
"github.com/cosmos/cosmos-sdk/tests"
|
||
|
)
|
||
|
|
||
|
func ExecuteWriteCheckErr(t *testing.T, cmdStr string, writes ...string) {
|
||
|
require.True(t, ExecuteWrite(t, cmdStr, writes...))
|
||
|
}
|
||
|
|
||
|
func ExecuteWrite(t *testing.T, cmdStr string, writes ...string) (exitSuccess bool) {
|
||
|
exitSuccess, _, _ = ExecuteWriteRetStdStreams(t, cmdStr, writes...)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func ExecuteWriteRetStdStreams(t *testing.T, cmdStr string, writes ...string) (bool, string, string) {
|
||
|
proc := tests.GoExecuteT(t, cmdStr)
|
||
|
|
||
|
// Enables use of interactive commands
|
||
|
for _, write := range writes {
|
||
|
_, err := proc.StdinPipe.Write([]byte(write + "\n"))
|
||
|
require.NoError(t, err)
|
||
|
}
|
||
|
|
||
|
// Read both stdout and stderr from the process
|
||
|
stdout, stderr, err := proc.ReadAll()
|
||
|
if err != nil {
|
||
|
fmt.Println("Err on proc.ReadAll()", err, cmdStr)
|
||
|
}
|
||
|
|
||
|
// Log output.
|
||
|
if len(stdout) > 0 {
|
||
|
t.Log("Stdout:", string(stdout))
|
||
|
}
|
||
|
if len(stderr) > 0 {
|
||
|
t.Log("Stderr:", string(stderr))
|
||
|
}
|
||
|
|
||
|
// Wait for process to exit
|
||
|
proc.Wait()
|
||
|
|
||
|
// Return succes, stdout, stderr
|
||
|
return proc.ExitState.Success(), string(stdout), string(stderr)
|
||
|
}
|