Skip to content

Commit

Permalink
Add e2e test for the TabletManager GetSchema RPC
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <mattalord@gmail.com>
  • Loading branch information
mattlord committed Feb 9, 2022
1 parent 2a4550d commit 1eea00f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions go/test/endtoend/tabletmanager/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ import (
"time"

"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"

"github.com/stretchr/testify/assert"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/test/endtoend/cluster"
)

var (
getSchemaT1Results = "CREATE TABLE `t1` (\n `id` bigint(20) NOT NULL,\n `value` varchar(16) DEFAULT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8"
getSchemaV1Results = fmt.Sprintf("CREATE ALGORITHM=UNDEFINED DEFINER=`%s`@`%s` SQL SECURITY DEFINER VIEW {{.DatabaseName}}.`v1` AS select {{.DatabaseName}}.`t1`.`id` AS `id`,{{.DatabaseName}}.`t1`.`value` AS `value` from {{.DatabaseName}}.`t1`", username, hostname)
)

// TabletCommands tests the basic tablet commands
func TestTabletCommands(t *testing.T) {
defer cluster.PanicHandler(t)
Expand Down Expand Up @@ -224,6 +230,20 @@ func TestShardReplicationFix(t *testing.T) {
assertNodeCount(t, result, int(3))
}

func TestGetSchema(t *testing.T) {
defer cluster.PanicHandler(t)

res, err := clusterInstance.VtctlclientProcess.ExecuteCommandWithOutput("GetSchema",
"-include-views", "-tables", "t1,v1",
fmt.Sprintf("%s-%d", clusterInstance.Cell, primaryTablet.TabletUID))
require.Nil(t, err)

t1Create := gjson.Get(res, "table_definitions.#(name==\"t1\").schema")
assert.Equal(t, getSchemaT1Results, t1Create.String())
v1Create := gjson.Get(res, "table_definitions.#(name==\"v1\").schema")
assert.Equal(t, getSchemaV1Results, v1Create.String())
}

func assertNodeCount(t *testing.T, result string, want int) {
resultMap := make(map[string]interface{})
err := json.Unmarshal([]byte(result), &resultMap)
Expand Down
3 changes: 2 additions & 1 deletion go/test/endtoend/tabletmanager/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ var (
id bigint,
value varchar(16),
primary key(id)
) Engine=InnoDB;
) Engine=InnoDB DEFAULT CHARSET=utf8;
CREATE VIEW v1 AS SELECT id, value FROM t1;
`

vSchema = `
Expand Down

0 comments on commit 1eea00f

Please sign in to comment.