Skip to content

Commit

Permalink
Add first server command tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey authored and rigelrozanski committed Mar 1, 2018
1 parent cdd33aa commit d694dbe
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
4 changes: 2 additions & 2 deletions server/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (c initCmd) initTendermintFiles(config *cfg.Config) error {
} else {
privValidator = tmtypes.GenPrivValidatorFS(privValFile)
privValidator.Save()
c.logger.Info("Genetated private validator", "path", privValFile)
c.logger.Info("Generated private validator", "path", privValFile)
}

// genesis file
Expand All @@ -130,7 +130,7 @@ func (c initCmd) initTendermintFiles(config *cfg.Config) error {
if err := genDoc.SaveAs(genFile); err != nil {
return err
}
c.logger.Info("Genetated genesis file", "path", genFile)
c.logger.Info("Generated genesis file", "path", genFile)
}
return nil
}
Expand Down
31 changes: 30 additions & 1 deletion server/init_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
package server

import "testing"
import (
"io/ioutil"
"os"
"testing"

"github.com/spf13/viper"
"github.com/stretchr/testify/require"

"github.com/tendermint/tmlibs/log"

"github.com/cosmos/cosmos-sdk/mock"
)

// setupViper creates a homedir to run inside,
// and returns a cleanup function to defer
func setupViper() func() {
rootDir, err := ioutil.TempDir("", "mock-sdk-cmd")
if err != nil {
panic(err) // fuck it!
}
viper.Set("home", rootDir)
return func() {
os.RemoveAll(rootDir)
}
}

func TestInit(t *testing.T) {
defer setupViper()()

logger := log.NewNopLogger()
cmd := InitCmd(mock.GenInitOptions, logger)
err := cmd.RunE(nil, nil)
require.NoError(t, err)
}
31 changes: 26 additions & 5 deletions server/start_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
package server

import (
"os"
"testing"

"github.com/spf13/viper"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/mock"
"github.com/tendermint/tmlibs/log"
)

func TestStart(t *testing.T) {
// app, cleanup, err := mock.SetupApp()
// if cleanup != nil {
// defer cleanup()
// }
defer setupViper()()

logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).
With("module", "mock-cmd")
// logger := log.NewNopLogger()
initCmd := InitCmd(mock.GenInitOptions, logger)
err := initCmd.RunE(nil, nil)
require.NoError(t, err)

// try to start up
// this should hang forever on success.... how to close???

rootDir := viper.GetString("home")
app, err := mock.NewApp(logger, rootDir)
require.NoError(t, err)
_ = StartCmd(app, logger)
// startCmd := StartCmd(app, logger)

// // TODO: test with tendermint
// err = startCmd.RunE(nil, nil)
// require.NoError(t, err)
// // TODO: init and start
}

0 comments on commit d694dbe

Please sign in to comment.