зеркало из https://github.com/github/vitess-gh.git
vttest: Provide Handle method "VtgateAddress".
This makes it easier to access vtgate in other tests.
This commit is contained in:
Родитель
18df41f909
Коммит
c12f03892f
|
@ -38,6 +38,25 @@ type Handle struct {
|
|||
dbname string
|
||||
}
|
||||
|
||||
// VtgateAddress returns the address under which vtgate is reachable e.g.
|
||||
// "localhost:15991".
|
||||
// An error is returned if the data is not available.
|
||||
func (hdl *Handle) VtgateAddress() (string, error) {
|
||||
if hdl.Data == nil {
|
||||
return "", errors.New("Data field in Handle is empty")
|
||||
}
|
||||
portName := "port"
|
||||
if vtgateProtocol() == "grpc" {
|
||||
portName = "grpc_port"
|
||||
}
|
||||
fport, ok := hdl.Data[portName]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("port %v not found in map", portName)
|
||||
}
|
||||
port := int(fport.(float64))
|
||||
return fmt.Sprintf("localhost:%d", port), nil
|
||||
}
|
||||
|
||||
// VitessOption is the type for generic options to be passed in to LaunchVitess.
|
||||
type VitessOption struct {
|
||||
// beforeRun is executed before we start run_local_database.py.
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package vttest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -48,22 +47,13 @@ func TestVitess(t *testing.T) {
|
|||
return
|
||||
}
|
||||
}()
|
||||
if hdl.Data == nil {
|
||||
t.Error("map is nil")
|
||||
return
|
||||
}
|
||||
portName := "port"
|
||||
if vtgateProtocol() == "grpc" {
|
||||
portName = "grpc_port"
|
||||
}
|
||||
fport, ok := hdl.Data[portName]
|
||||
if !ok {
|
||||
t.Errorf("port %v not found in map", portName)
|
||||
return
|
||||
}
|
||||
port := int(fport.(float64))
|
||||
ctx := context.Background()
|
||||
conn, err := vtgateconn.DialProtocol(ctx, vtgateProtocol(), fmt.Sprintf("localhost:%d", port), 5*time.Second, "")
|
||||
vtgateAddr, err := hdl.VtgateAddress()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
conn, err := vtgateconn.DialProtocol(ctx, vtgateProtocol(), vtgateAddr, 5*time.Second, "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
|
Загрузка…
Ссылка в новой задаче