本文整理匯總了Golang中github.com/youtube/vitess/go/vt/vtctl/vtctlclient.VtctlClient.ExecuteVtctlCommand方法的典型用法代碼示例。如果您正苦於以下問題:Golang VtctlClient.ExecuteVtctlCommand方法的具體用法?Golang VtctlClient.ExecuteVtctlCommand怎麽用?Golang VtctlClient.ExecuteVtctlCommand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/youtube/vitess/go/vt/vtctl/vtctlclient.VtctlClient
的用法示例。
在下文中一共展示了VtctlClient.ExecuteVtctlCommand方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestSuite
// TestSuite runs the test suite on the given topo server and client
func TestSuite(t *testing.T, ts topo.Server, client vtctlclient.VtctlClient) {
ctx := context.Background()
// Create a fake tablet
tablet := &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{Cell: "cell1", Uid: 1},
Hostname: "localhost",
Ip: "10.11.12.13",
PortMap: map[string]int32{
"vt": 3333,
"mysql": 3334,
},
Tags: map[string]string{"tag": "value"},
Keyspace: "test_keyspace",
Type: topodatapb.TabletType_MASTER,
}
if err := ts.CreateTablet(ctx, tablet); err != nil {
t.Errorf("CreateTablet: %v", err)
}
// run a command that's gonna return something on the log channel
stream, err := client.ExecuteVtctlCommand(ctx, []string{"ListAllTablets", "cell1"}, 30*time.Second)
if err != nil {
t.Fatalf("Remote error: %v", err)
}
got, err := stream.Recv()
if err != nil {
t.Fatalf("failed to get first line: %v", err)
}
expected := "cell1-0000000001 test_keyspace <null> master localhost:3333 localhost:3334 [tag: \"value\"]\n"
if logutil.EventString(got) != expected {
t.Errorf("Got unexpected log line '%v' expected '%v'", got.String(), expected)
}
got, err = stream.Recv()
if err != io.EOF {
t.Errorf("Didn't get end of log stream: %v %v", got, err)
}
// run a command that's gonna fail
stream, err = client.ExecuteVtctlCommand(ctx, []string{"ListAllTablets", "cell2"}, 30*time.Second)
if err != nil {
t.Fatalf("Remote error: %v", err)
}
got, err = stream.Recv()
expected = "node doesn't exist"
if err == nil || !strings.Contains(err.Error(), expected) {
t.Fatalf("Unexpected remote error, got: '%v' was expecting to find '%v'", err, expected)
}
// run a command that's gonna panic
stream, err = client.ExecuteVtctlCommand(ctx, []string{"Panic"}, 30*time.Second)
if err != nil {
t.Fatalf("Remote error: %v", err)
}
got, err = stream.Recv()
expected1 := "this command panics on purpose"
expected2 := "uncaught vtctl panic"
if err == nil || !strings.Contains(err.Error(), expected1) || !strings.Contains(err.Error(), expected2) {
t.Fatalf("Unexpected remote error, got: '%v' was expecting to find '%v' and '%v'", err, expected1, expected2)
}
// and clean up the tablet
if err := ts.DeleteTablet(ctx, tablet.Alias); err != nil {
t.Errorf("DeleteTablet: %v", err)
}
}
示例2: TestSuite
// TestSuite runs the test suite on the given topo server and client
func TestSuite(t *testing.T, ts topo.Server, client vtctlclient.VtctlClient) {
ctx := context.Background()
// Create a fake tablet
tablet := &topo.Tablet{
Alias: topo.TabletAlias{Cell: "cell1", Uid: 1},
Hostname: "localhost",
IPAddr: "10.11.12.13",
Portmap: map[string]int{
"vt": 3333,
"mysql": 3334,
},
Tags: map[string]string{"tag": "value"},
Keyspace: "test_keyspace",
Type: topo.TYPE_MASTER,
}
if err := ts.CreateTablet(ctx, tablet); err != nil {
t.Errorf("CreateTablet: %v", err)
}
// run a command that's gonna return something on the log channel
logs, errFunc, err := client.ExecuteVtctlCommand(ctx, []string{"ListAllTablets", "cell1"}, 30*time.Second, 10*time.Second)
if err != nil {
t.Fatalf("Remote error: %v", err)
}
count := 0
for e := range logs {
expected := "cell1-0000000001 test_keyspace <null> master localhost:3333 localhost:3334 [tag: \"value\"]\n"
if e.String() != expected {
t.Errorf("Got unexpected log line '%v' expected '%v'", e.String(), expected)
}
count++
}
if count != 1 {
t.Errorf("Didn't get expected log line only, got %v lines", count)
}
if err := errFunc(); err != nil {
t.Fatalf("Remote error: %v", err)
}
// run a command that's gonna fail
logs, errFunc, err = client.ExecuteVtctlCommand(ctx, []string{"ListAllTablets", "cell2"}, 30*time.Second, 10*time.Second)
if err != nil {
t.Fatalf("Remote error: %v", err)
}
if e, ok := <-logs; ok {
t.Errorf("Got unexpected line for logs: %v", e.String())
}
expected := "node doesn't exist"
if err := errFunc(); err == nil || !strings.Contains(err.Error(), expected) {
t.Fatalf("Unexpected remote error, got: '%v' was expecting to find '%v'", err, expected)
}
// run a command that's gonna panic
logs, errFunc, err = client.ExecuteVtctlCommand(ctx, []string{"Panic"}, 30*time.Second, 10*time.Second)
if err != nil {
t.Fatalf("Remote error: %v", err)
}
if e, ok := <-logs; ok {
t.Errorf("Got unexpected line for logs: %v", e.String())
}
expected1 := "this command panics on purpose"
expected2 := "uncaught vtctl panic"
if err := errFunc(); err == nil || !strings.Contains(err.Error(), expected1) || !strings.Contains(err.Error(), expected2) {
t.Fatalf("Unexpected remote error, got: '%v' was expecting to find '%v' and '%v'", err, expected1, expected2)
}
}