forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
996cafe
commit 8ab77e2
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |