Skip to content

Commit 4ac089f

Browse files
committed
json testing, addressed init option PR comments
1 parent 748a1e9 commit 4ac089f

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ GOTOOLS = github.com/mitchellh/gox \
33
github.com/rigelrozanski/shelldown/cmd/shelldown
44
TUTORIALS=$(shell find docs/guide -name "*md" -type f)
55

6-
EXAMPLES := counter eyes basecoin
6+
EXAMPLES := counter eyes basecoin
77
INSTALL_EXAMPLES := $(addprefix install_,${EXAMPLES})
88
TEST_EXAMPLES := $(addprefix testex_,${EXAMPLES})
99

@@ -37,6 +37,7 @@ test_unit:
3737
@go test `glide novendor`
3838

3939
test_cli: $(TEST_EXAMPLES)
40+
./tests/cli/init-server.sh
4041
# sudo apt-get install jq
4142
# wget "https://raw.githubusercontent.com/kward/shunit2/master/source/2.1/src/shunit2"
4243

server/commands/init.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var (
3131

3232
func init() {
3333
InitCmd.Flags().String(FlagChainID, "test_chain_id", "Chain ID")
34-
InitCmd.Flags().StringSlice(FlagOption, []string{}, "Genesis option in the format <app>/<option>/<value>")
34+
InitCmd.Flags().StringSliceP(FlagOption, "p", []string{}, "Genesis option in the format <app>/<option>/<value>")
3535
}
3636

3737
// returns 1 iff it set a file, otherwise 0 (so we can add them)
@@ -67,12 +67,13 @@ func initCmd(cmd *cobra.Command, args []string) error {
6767
return errors.New("Address must be 20-bytes in hex")
6868
}
6969

70-
var options []string
7170
var optionsStr string
72-
sep := ",\n "
7371
optionsRaw := viper.GetStringSlice(FlagOption)
7472
if len(optionsRaw) > 0 {
75-
optionsStr = sep
73+
74+
var options []string
75+
sep := ",\n "
76+
7677
for i := 0; i < len(optionsRaw); i++ {
7778
s := strings.SplitN(optionsRaw[i], "/", 3)
7879
if len(s) != 3 {
@@ -87,8 +88,8 @@ func initCmd(cmd *cobra.Command, args []string) error {
8788
option := `"` + s[0] + `/` + s[1] + `", ` + s[2]
8889
options = append(options, option)
8990
}
91+
optionsStr = sep + strings.Join(options[:], sep)
9092
}
91-
optionsStr += strings.Join(options[:], sep)
9293

9394
genesis := GetGenesisJSON(viper.GetString(FlagChainID), userAddr, optionsStr)
9495
return CreateGenesisValidatorFiles(cfg, genesis, cmd.Root().Name())

server/commands/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func preRunSetup(cmd *cobra.Command, args []string) (err error) {
3535
return nil
3636
}
3737

38+
// SetUpRoot - initialize the root command
3839
func SetUpRoot(cmd *cobra.Command) {
3940
cmd.PersistentPreRunE = preRunSetup
4041
cmd.PersistentFlags().String(FlagLogLevel, defaultLogLevel, "Log level")

tests/cli/init-server.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,36 @@ test01initOption() {
88
rm -rf "$BASE"
99
mkdir -p "$BASE"
1010

11-
SERVER="${BASE}/server"
12-
GENESIS_FILE=${SERVER}/genesis.json
11+
SERVE_DIR="${BASE}/server"
12+
GENESIS_FILE=${SERVE_DIR}/genesis.json
1313
HEX="deadbeef1234deadbeef1234deadbeef1234aaaa"
1414

15-
${SERVER_EXE} init ${HEX} --home="$SERVER" --option=app1/key1/val1 --option=app2/key2/val2 >/dev/null
15+
${SERVER_EXE} init ${HEX} --home="$SERVE_DIR" -p=app1/key1/val1 -p='"app2/key2/{""name"": ""joe"", ""age"": ""100""}"' >/dev/null
1616
if ! assertTrue "line=${LINENO}" $?; then return 1; fi
1717

1818
OPTION1KEY=$(cat ${GENESIS_FILE} | jq '.app_options.plugin_options[2]')
1919
OPTION1VAL=$(cat ${GENESIS_FILE} | jq '.app_options.plugin_options[3]')
2020
OPTION2KEY=$(cat ${GENESIS_FILE} | jq '.app_options.plugin_options[4]')
2121
OPTION2VAL=$(cat ${GENESIS_FILE} | jq '.app_options.plugin_options[5]')
22+
OPTION2VALEXPECTED=$(echo '{"name": "joe", "age": "100"}' | jq '.')
2223

2324
assertEquals "line=${LINENO}" '"app1/key1"' $OPTION1KEY
2425
assertEquals "line=${LINENO}" '"val1"' $OPTION1VAL
2526
assertEquals "line=${LINENO}" '"app2/key2"' $OPTION2KEY
26-
assertEquals "line=${LINENO}" '"val2"' $OPTION2VAL
27+
assertEquals "line=${LINENO}" "$OPTION2VALEXPECTED" "$OPTION2VAL"
28+
}
29+
30+
test02runServer() {
31+
# Attempt to begin the server with the custom genesis
32+
SERVER_LOG=$BASE/${SERVER_EXE}.log
33+
startServer $SERVE_DIR $SERVER_LOG
34+
}
35+
36+
oneTimeTearDown() {
37+
quickTearDown
2738
}
2839

2940
# load and run these tests with shunit2!
30-
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
31-
. $DIR/shunit2
41+
CLI_DIR=$GOPATH/src/github.com/cosmos/cosmos-sdk/tests/cli
42+
. $CLI_DIR/common.sh
43+
. $CLI_DIR/shunit2

0 commit comments

Comments
 (0)