TestStartStandAlone without cobra

This commit is contained in:
Christopher Goes 2018-04-03 20:19:41 +02:00
parent 12f4a21d03
commit 457092d662
No known key found for this signature in database
GPG Key ID: E828D98232D328D3
1 changed files with 20 additions and 10 deletions

View File

@ -1,6 +1,7 @@
package server
import (
"io/ioutil"
"os"
"testing"
"time"
@ -9,25 +10,34 @@ import (
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/mock"
"github.com/tendermint/abci/server"
"github.com/tendermint/tmlibs/log"
)
func TestStartStandAlone(t *testing.T) {
defer setupViper(t)()
home, err := ioutil.TempDir("", "mock-sdk-cmd")
defer func() {
os.RemoveAll(home)
}()
logger := log.NewNopLogger()
initCmd := InitCmd(mock.GenInitOptions, logger)
err := initCmd.RunE(nil, nil)
err = initCmd.RunE(nil, nil)
require.NoError(t, err)
// set up app and start up
viper.Set(flagWithTendermint, false)
viper.Set(flagAddress, "localhost:11122")
startCmd := StartCmd(mock.NewApp, logger)
startCmd.Flags().Set(flagAddress, FreeTCPAddr(t)) // set to a new free address
timeout := time.Duration(10) * time.Second
app, err := mock.NewApp(home, logger)
require.Nil(t, err)
svr, err := server.NewServer(FreeTCPAddr(t), "socket", app)
require.Nil(t, err, "Error creating listener")
svr.SetLogger(logger.With("module", "abci-server"))
svr.Start()
timer := time.NewTimer(time.Duration(5) * time.Second)
select {
case <-timer.C:
svr.Stop()
}
close(RunOrTimeout(startCmd, timeout, t))
}
func TestStartWithTendermint(t *testing.T) {
@ -43,7 +53,7 @@ func TestStartWithTendermint(t *testing.T) {
viper.Set(flagWithTendermint, true)
startCmd := StartCmd(mock.NewApp, logger)
startCmd.Flags().Set(flagAddress, FreeTCPAddr(t)) // set to a new free address
timeout := time.Duration(10) * time.Second
timeout := time.Duration(5) * time.Second
close(RunOrTimeout(startCmd, timeout, t))
}