started gaia go-bash cli testing
This commit is contained in:
parent
996cafe972
commit
8ab77e2ab5
42
cmd/gaia/cmd/app_test.go
Normal file
42
cmd/gaia/cmd/app_test.go
Normal file
@ -0,0 +1,42 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
)
|
||||
|
||||
func TestGaiaCLI(t *testing.T) {
|
||||
|
||||
_, out := tests.ExecuteT(t, "gaiad init")
|
||||
var initRes map[string]interface{}
|
||||
outCut := "{" + strings.SplitN(out, "{", 2)[1]
|
||||
err := json.Unmarshal([]byte(outCut), &initRes)
|
||||
require.NoError(t, err, "out %v outCut %v err %v", out, outCut, err)
|
||||
masterKey := (initRes["secret"]).(string)
|
||||
_ = masterKey
|
||||
|
||||
//wc1, _ := tests.GoExecuteT(t, "gaiacli keys add foo --recover")
|
||||
//time.Sleep(time.Second)
|
||||
//_, err = wc1.Write([]byte("1234567890\n"))
|
||||
//time.Sleep(time.Second)
|
||||
//_, err = wc1.Write([]byte(masterKey + "\n"))
|
||||
//time.Sleep(time.Second)
|
||||
//out = <-outChan
|
||||
//wc1.Close()
|
||||
//fmt.Println(out)
|
||||
|
||||
//_, out = tests.ExecuteT(t, "gaiacli keys show foo")
|
||||
//fooAddr := strings.TrimLeft(out, "foo\t")
|
||||
|
||||
//wc2, _ := tests.GoExecuteT(t, "gaiad start")
|
||||
//defer wc2.Close()
|
||||
//time.Sleep(time.Second)
|
||||
|
||||
//_, out = tests.ExecuteT(t, fmt.Sprintf("gaiacli account %v", fooAddr))
|
||||
//fmt.Println(fooAddr)
|
||||
}
|
||||
49
tests/gobash.go
Normal file
49
tests/gobash.go
Normal file
@ -0,0 +1,49 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func getCmd(t *testing.T, command string) *exec.Cmd {
|
||||
|
||||
//split command into command and args
|
||||
split := strings.Split(command, " ")
|
||||
require.True(t, len(split) > 0, "no command provided")
|
||||
|
||||
var cmd *exec.Cmd
|
||||
if len(split) == 1 {
|
||||
cmd = exec.Command(split[0])
|
||||
} else {
|
||||
cmd = exec.Command(split[0], split[1:]...)
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Execute the command, return standard output and error
|
||||
func ExecuteT(t *testing.T, command string) (pipe io.WriteCloser, out string) {
|
||||
cmd := getCmd(t, command)
|
||||
pipe, err := cmd.StdinPipe()
|
||||
require.NoError(t, err)
|
||||
bz, err := cmd.CombinedOutput()
|
||||
require.NoError(t, err)
|
||||
out = strings.Trim(string(bz), "\n") //trim any new lines
|
||||
return pipe, out
|
||||
}
|
||||
|
||||
// Asynchronously execute the command, return standard output and error
|
||||
func GoExecuteT(t *testing.T, command string) (pipe io.WriteCloser, outChan chan string) {
|
||||
cmd := getCmd(t, command)
|
||||
pipe, err := cmd.StdinPipe()
|
||||
require.NoError(t, err)
|
||||
go func() {
|
||||
bz, err := cmd.CombinedOutput()
|
||||
require.NoError(t, err)
|
||||
outChan <- strings.Trim(string(bz), "\n") //trim any new lines
|
||||
}()
|
||||
return pipe, outChan
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user