Skip to content

Commit

Permalink
Simple integration tests for {base,demo}coind
Browse files Browse the repository at this point in the history
Closes: #1632
  • Loading branch information
alessio committed Aug 22, 2018
1 parent 29634bf commit 56a98cb
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ jobs:
export PATH="$GOBIN:$PATH"
make test_cli
test_examples:
<<: *defaults

This comment has been minimized.

Copy link
@ValarDragon

ValarDragon Aug 23, 2018

Contributor

Can we rename test cli to integration tests, and merge the two? (Cli tests don't bottleneck ci, so making a new test would just increase our container usage)

Alternatively this could go in test cover.

This comment has been minimized.

Copy link
@alessio

alessio via email Aug 23, 2018

Author Contributor
parallelism: 1
steps:
- attach_workspace:
at: /tmp/workspace
- restore_cache:
key: v1-pkg-cache
- restore_cache:
key: v1-tree-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Test examples
command: |
export PATH="$GOBIN:$PATH"
make test_examples
test_sim_modules:
<<: *defaults
parallelism: 1
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ test: test_unit
test_cli:
@go test -count 1 -p 1 `go list github.com/cosmos/cosmos-sdk/cmd/gaia/cli_test` -tags=cli_test

test_examples:
@go test -count 1 -p 1 `go list github.com/cosmos/cosmos-sdk/examples/basecoin/cli_test` -tags=cli_test
@go test -count 1 -p 1 `go list github.com/cosmos/cosmos-sdk/examples/democoin/cli_test` -tags=cli_test

test_unit:
@go test $(PACKAGES_NOSIMULATION)

Expand Down
52 changes: 52 additions & 0 deletions examples/basecoin/cli_test/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package clitest

import (
"encoding/json"
"fmt"
"os"
"testing"

"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/tests"
"github.com/stretchr/testify/require"
)

var (
basecoindHome = ""
)

func init() {
basecoindHome = getTestingHomeDir()
}

func TestInitStartSequence(t *testing.T) {
os.RemoveAll(basecoindHome)
servAddr, port, err := server.FreeTCPAddr()
require.NoError(t, err)
executeInit(t)
executeStart(t, servAddr, port)
}

func executeInit(t *testing.T) {
var (
chainID string
initRes map[string]json.RawMessage
)
out := tests.ExecuteT(t, fmt.Sprintf("basecoind --home=%s init", basecoindHome), "")
err := json.Unmarshal([]byte(out), &initRes)
require.NoError(t, err)
err = json.Unmarshal(initRes["chain_id"], &chainID)
require.NoError(t, err)
}

func executeStart(t *testing.T, servAddr, port string) {
proc := tests.GoExecuteTWithStdout(t, fmt.Sprintf("basecoind start --home=%s --rpc.laddr=%v", basecoindHome, servAddr))
defer proc.Stop(false)
tests.WaitForTMStart(port)
}

func getTestingHomeDir() string {
tmpDir := os.TempDir()
basecoindHome := fmt.Sprintf("%s%s.test_basecoind", tmpDir, string(os.PathSeparator))
return basecoindHome
}
52 changes: 52 additions & 0 deletions examples/democoin/cli_test/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package clitest

import (
"encoding/json"
"fmt"
"os"
"testing"

"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/tests"
"github.com/stretchr/testify/require"
)

var (
democoindHome = ""
)

func init() {
democoindHome = getTestingHomeDir()
}

func TestInitStartSequence(t *testing.T) {
os.RemoveAll(democoindHome)
servAddr, port, err := server.FreeTCPAddr()
require.NoError(t, err)
executeInit(t)
executeStart(t, servAddr, port)
}

func executeInit(t *testing.T) {
var (
chainID string
initRes map[string]json.RawMessage
)
out := tests.ExecuteT(t, fmt.Sprintf("democoind --home=%s init", democoindHome), "")
err := json.Unmarshal([]byte(out), &initRes)
require.NoError(t, err)
err = json.Unmarshal(initRes["chain_id"], &chainID)
require.NoError(t, err)
}

func executeStart(t *testing.T, servAddr, port string) {
proc := tests.GoExecuteTWithStdout(t, fmt.Sprintf("democoind start --home=%s --rpc.laddr=%v", democoindHome, servAddr))
defer proc.Stop(false)
tests.WaitForTMStart(port)
}

func getTestingHomeDir() string {
tmpDir := os.TempDir()
democoindHome := fmt.Sprintf("%s%s.test_democoind", tmpDir, string(os.PathSeparator))
return democoindHome
}

0 comments on commit 56a98cb

Please sign in to comment.