From 56a98cb04742a17e368ad0d98afe31ae02568964 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Wed, 22 Aug 2018 18:17:15 +0100 Subject: [PATCH 1/3] Simple integration tests for {base,demo}coind Closes: #1632 --- .circleci/config.yml | 16 ++++++++ Makefile | 4 ++ examples/basecoin/cli_test/cli_test.go | 52 ++++++++++++++++++++++++++ examples/democoin/cli_test/cli_test.go | 52 ++++++++++++++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 examples/basecoin/cli_test/cli_test.go create mode 100644 examples/democoin/cli_test/cli_test.go diff --git a/.circleci/config.yml b/.circleci/config.yml index 90a8393c1..286cacb7d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -81,6 +81,22 @@ jobs: export PATH="$GOBIN:$PATH" make test_cli + test_examples: + <<: *defaults + 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 diff --git a/Makefile b/Makefile index b35e3f5c9..de5f6956f 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/examples/basecoin/cli_test/cli_test.go b/examples/basecoin/cli_test/cli_test.go new file mode 100644 index 000000000..3a33135e3 --- /dev/null +++ b/examples/basecoin/cli_test/cli_test.go @@ -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 +} diff --git a/examples/democoin/cli_test/cli_test.go b/examples/democoin/cli_test/cli_test.go new file mode 100644 index 000000000..2db2fff09 --- /dev/null +++ b/examples/democoin/cli_test/cli_test.go @@ -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 +} From ceb33ca464b051602c5f3d94edcba5b491f334ad Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Thu, 23 Aug 2018 08:47:12 +0100 Subject: [PATCH 2/3] Rename test_cli to integration_tests Move `make test_examples` into integraton_tests. --- .circleci/config.yml | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 286cacb7d..269d4ca94 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -63,7 +63,7 @@ jobs: export PATH="$GOBIN:$PATH" make test_lint - test_cli: + integration_tests: <<: *defaults parallelism: 1 steps: @@ -80,21 +80,6 @@ jobs: command: | export PATH="$GOBIN:$PATH" make test_cli - - test_examples: - <<: *defaults - 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: @@ -236,7 +221,7 @@ workflows: - lint: requires: - setup_dependencies - - test_cli: + - integration_tests: requires: - setup_dependencies - test_sim_modules: From c02456b8a1f750f368d9ede05fbafb569b118ea4 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Thu, 23 Aug 2018 12:37:01 +0100 Subject: [PATCH 3/3] Update PENDING.md --- PENDING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/PENDING.md b/PENDING.md index a5f612236..61524a525 100644 --- a/PENDING.md +++ b/PENDING.md @@ -56,6 +56,7 @@ IMPROVEMENTS * SDK * [tools] Make get_vendor_deps deletes `.vendor-new` directories, in case scratch files are present. + * [cli] \#1632 Add integration tests to ensure `basecoind init && basecoind` start sequences run successfully for both `democoin` and `basecoin` examples. * Tendermint