From 0edd1297a9a90b2569c117bbc38a901d468a9efd Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 19 Jun 2017 17:07:12 +0200 Subject: [PATCH] Got basic key test working --- .gitignore | 1 + Makefile | 17 ++++++++++++++--- tests/keys.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100755 tests/keys.sh diff --git a/.gitignore b/.gitignore index f37225baa..d19e6457f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.swp *.swo vendor +shunit2 diff --git a/Makefile b/Makefile index ca9703399..e40d0e6ff 100644 --- a/Makefile +++ b/Makefile @@ -8,13 +8,24 @@ docs: @go get github.com/davecheney/godoc2md godoc2md $(REPO) > README.md -all: install test +all: get_vendor_deps install test install: go install ./cmd/keys -test: +test: test_unit test_cli + +test_unit: go test `glide novendor` + #go run tests/tendermint/*.go + +test_cli: tests/shunit2 + # sudo apt-get install jq + @./tests/keys.sh + +tests/shunit2: + wget "https://raw.githubusercontent.com/kward/shunit2/master/source/2.1/src/shunit2" \ + -q -O tests/shunit2 get_vendor_deps: ensure_tools @rm -rf vendor/ @@ -30,7 +41,7 @@ prepgen: install go install ./vendor/github.com/stretchr/testify/require go install ./vendor/golang.org/x/crypto/bcrypt -codegen: +codegen: @echo "--> regenerating all interface wrappers" @gen @echo "Done!" diff --git a/tests/keys.sh b/tests/keys.sh new file mode 100755 index 000000000..b4bdcdd40 --- /dev/null +++ b/tests/keys.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +EXE=keys + +oneTimeSetUp() { + PASS=qwertyuiop + export TM_HOME=$HOME/.keys_test + rm -rf $TM_HOME + assertTrue $? +} + +newKey(){ + assertNotNull "keyname required" "$1" + KEYPASS=${2:-qwertyuiop} + (echo $KEYPASS; echo $KEYPASS) | ${EXE} new $1 >/dev/null 2>&1 + assertTrue "created $1" $? +} + +testMakeKeys() { + USER=demouser + assertFalse "already user $USER" "${EXE} list | grep $USER" + assertEquals "1" `${EXE} list | wc -l` + newKey $USER + assertTrue "no user $USER" "${EXE} list | grep $USER" + assertEquals "2" `${EXE} list | wc -l` +} + +# load and run these tests with shunit2! +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory +. $DIR/shunit2