Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2e test for the TabletManager GetSchema RPC #9658

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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