Skip to content

Commit

Permalink
Merge #40602
Browse files Browse the repository at this point in the history
40602: cli: Add some tests for the locality setting features of cockroach demo r=knz a=rohany

Added some tests for locality settings in cockroach demo.

Release justification: Low risk tests for an existing feature.

Release note: None

Co-authored-by: Rohan Yadav <[email protected]>
  • Loading branch information
craig[bot] and Rohan Yadav committed Sep 24, 2019
2 parents 430bcb9 + bbb4c25 commit d79fea5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
40 changes: 40 additions & 0 deletions pkg/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,45 @@ func Example_logging() {
// 1
}

func Example_demo_locality() {
c := newCLITest(cliTestParams{noServer: true})
defer c.cleanup()

testData := [][]string{
{`demo`, `--nodes`, `3`, `-e`, `select node_id, locality from crdb_internal.gossip_nodes order by node_id`},
{`demo`, `--nodes`, `9`, `-e`, `select node_id, locality from crdb_internal.gossip_nodes order by node_id`},
{`demo`, `--nodes`, `3`, `--demo-locality=region=us-east1:region=us-east2:region=us-east3`,
`-e`, `select node_id, locality from crdb_internal.gossip_nodes order by node_id`},
}
setCLIDefaultsForTests()
for _, cmd := range testData {
c.RunWithArgs(cmd)
}

// Output:
// demo --nodes 3 -e select node_id, locality from crdb_internal.gossip_nodes order by node_id
// node_id locality
// 1 region=us-east1,az=b
// 2 region=us-east1,az=c
// 3 region=us-east1,az=d
// demo --nodes 9 -e select node_id, locality from crdb_internal.gossip_nodes order by node_id
// node_id locality
// 1 region=us-east1,az=b
// 2 region=us-east1,az=c
// 3 region=us-east1,az=d
// 4 region=us-west1,az=a
// 5 region=us-west1,az=b
// 6 region=us-west1,az=c
// 7 region=europe-west1,az=b
// 8 region=europe-west1,az=c
// 9 region=europe-west1,az=d
// demo --nodes 3 --demo-locality=region=us-east1:region=us-east2:region=us-east3 -e select node_id, locality from crdb_internal.gossip_nodes order by node_id
// node_id locality
// 1 region=us-east1
// 2 region=us-east2
// 3 region=us-east3
}

func Example_demo() {
c := newCLITest(cliTestParams{noServer: true})
defer c.cleanup()
Expand All @@ -485,6 +524,7 @@ func Example_demo() {
{`demo`, `startrek`, `-e`, `show databases`},
{`demo`, `startrek`, `-e`, `show databases`, `--format=table`},
}
setCLIDefaultsForTests()
for _, cmd := range testData {
c.RunWithArgs(cmd)
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/cli/interactive_tests/test_demo_locality_error.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! /usr/bin/env expect -f

source [file join [file dirname $argv0] common.tcl]

start_test "Expect error with incorrect demo locality settings"

# Test failure with less localities than expected.
spawn $argv demo --nodes 3 --demo-locality=region=us-east1:region=us-east2
# wait for the CLI to start up
eexpect "Error: number of localities specified must equal number of nodes"
eexpect eof

# Test failure with more localities than expected.
spawn $argv demo --nodes 3 --demo-locality=region=us-east1:region=us-east2:region=us-east3:region=us-east4
# wait for the CLI to start up
eexpect "Error: number of localities specified must equal number of nodes"
eexpect eof

end_test

0 comments on commit d79fea5

Please sign in to comment.