Skip to content

Commit

Permalink
add testdata.Path interface
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkerou committed Jun 30, 2017
1 parent 10a0692 commit ebe3a48
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion benchmark/worker/benchmark_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func createConns(config *testpb.ClientConfig) ([]*grpc.ClientConn, func(), error

// Check and set security options.
if config.SecurityParams != nil {
creds, err := credentials.NewClientTLSFromFile(testdata.Path("testdata/ca.pem"), config.SecurityParams.ServerHostOverride)
creds, err := credentials.NewClientTLSFromFile(testdata.Path("ca.pem"), config.SecurityParams.ServerHostOverride)
if err != nil {
return nil, nil, grpc.Errorf(codes.InvalidArgument, "failed to create TLS credentials %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/worker/benchmark_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func startBenchmarkServer(config *testpb.ServerConfig, serverPort int) (*benchma

// Set security options.
if config.SecurityParams != nil {
creds, err := credentials.NewServerTLSFromFile(testdata.Path("testdata/server1.pem"), testdata.Path("testdata/server1.key"))
creds, err := credentials.NewServerTLSFromFile(testdata.Path("server1.pem"), testdata.Path("server1.key"))
if err != nil {
grpclog.Fatalf("failed to generate credentials %v", err)
}
Expand Down
8 changes: 4 additions & 4 deletions clientconn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestDialTimeout(t *testing.T) {
}

func TestTLSDialTimeout(t *testing.T) {
creds, err := credentials.NewClientTLSFromFile(testdata.Path("testdata/ca.pem"), "x.test.youtube.com")
creds, err := credentials.NewClientTLSFromFile(testdata.Path("ca.pem"), "x.test.youtube.com")
if err != nil {
t.Fatalf("Failed to create credentials %v", err)
}
Expand All @@ -68,7 +68,7 @@ func TestDefaultAuthority(t *testing.T) {

func TestTLSServerNameOverwrite(t *testing.T) {
overwriteServerName := "over.write.server.name"
creds, err := credentials.NewClientTLSFromFile(testdata.Path("testdata/ca.pem"), overwriteServerName)
creds, err := credentials.NewClientTLSFromFile(testdata.Path("ca.pem"), overwriteServerName)
if err != nil {
t.Fatalf("Failed to create credentials %v", err)
}
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestWithAuthority(t *testing.T) {

func TestWithAuthorityAndTLS(t *testing.T) {
overwriteServerName := "over.write.server.name"
creds, err := credentials.NewClientTLSFromFile(testdata.Path("testdata/ca.pem"), overwriteServerName)
creds, err := credentials.NewClientTLSFromFile(testdata.Path("ca.pem"), overwriteServerName)
if err != nil {
t.Fatalf("Failed to create credentials %v", err)
}
Expand Down Expand Up @@ -167,7 +167,7 @@ func (c securePerRPCCredentials) RequireTransportSecurity() bool {
}

func TestCredentialsMisuse(t *testing.T) {
tlsCreds, err := credentials.NewClientTLSFromFile(testdata.Path("testdata/ca.pem"), "x.test.youtube.com")
tlsCreds, err := credentials.NewClientTLSFromFile(testdata.Path("ca.pem"), "x.test.youtube.com")
if err != nil {
t.Fatalf("Failed to create authenticator %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions credentials/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func clientHandle(t *testing.T, hs func(net.Conn, string) (AuthInfo, error), lis

// Server handshake implementation in gRPC.
func gRPCServerHandshake(conn net.Conn) (AuthInfo, error) {
serverTLS, err := NewServerTLSFromFile(testdata.Path("testdata/server1.pem"), testdata.Path("testdata/server1.key"))
serverTLS, err := NewServerTLSFromFile(testdata.Path("server1.pem"), testdata.Path("server1.key"))
if err != nil {
return nil, err
}
Expand All @@ -183,7 +183,7 @@ func gRPCClientHandshake(conn net.Conn, lisAddr string) (AuthInfo, error) {
}

func tlsServerHandshake(conn net.Conn) (AuthInfo, error) {
cert, err := tls.LoadX509KeyPair(testdata.Path("testdata/server1.pem"), testdata.Path("testdata/server1.key"))
cert, err := tls.LoadX509KeyPair(testdata.Path("server1.pem"), testdata.Path("server1.key"))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion examples/route_guide/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (

var (
tls = flag.Bool("tls", false, "Connection uses TLS if true, else plain TCP")
caFile = flag.String("ca_file", testdata.Path("testdata/ca.pem"), "The file containning the CA root cert file")
caFile = flag.String("ca_file", testdata.Path("ca.pem"), "The file containning the CA root cert file")
serverAddr = flag.String("server_addr", "127.0.0.1:10000", "The server address in the format of host:port")
serverHostOverride = flag.String("server_host_override", "x.test.youtube.com", "The server name use to verify the hostname returned by TLS handshake")
)
Expand Down
4 changes: 2 additions & 2 deletions examples/route_guide/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ import (

var (
tls = flag.Bool("tls", false, "Connection uses TLS if true, else plain TCP")
certFile = flag.String("cert_file", testdata.Path("testdata/server1.pem"), "The TLS cert file")
keyFile = flag.String("key_file", testdata.Path("testdata/server1.key"), "The TLS key file")
certFile = flag.String("cert_file", testdata.Path("server1.pem"), "The TLS cert file")
keyFile = flag.String("key_file", testdata.Path("server1.key"), "The TLS key file")
jsonDBFile = flag.String("json_db_file", "testdata/route_guide_db.json", "A json file containing a list of features")
port = flag.Int("port", 10000, "The server port")
)
Expand Down
2 changes: 1 addition & 1 deletion interop/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func main() {
var creds credentials.TransportCredentials
if *testCA {
var err error
creds, err = credentials.NewClientTLSFromFile(testdata.Path("testdata/ca.pem"), sn)
creds, err = credentials.NewClientTLSFromFile(testdata.Path("ca.pem"), sn)
if err != nil {
grpclog.Fatalf("Failed to create TLS credentials %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions interop/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (

var (
useTLS = flag.Bool("use_tls", false, "Connection uses TLS if true, else plain TCP")
certFile = flag.String("tls_cert_file", testdata.Path("testdata/server1.pem"), "The TLS cert file")
keyFile = flag.String("tls_key_file", testdata.Path("testdata/server1.key"), "The TLS key file")
certFile = flag.String("tls_cert_file", testdata.Path("server1.pem"), "The TLS cert file")
keyFile = flag.String("tls_key_file", testdata.Path("server1.key"), "The TLS key file")
port = flag.Int("port", 10000, "The server port")
)

Expand Down
2 changes: 1 addition & 1 deletion stress/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func newConn(address string, useTLS, testCA bool, tlsServerName string) (*grpc.C
var creds credentials.TransportCredentials
if testCA {
var err error
creds, err = credentials.NewClientTLSFromFile(testdata.Path("testdata/ca.pem"), sn)
creds, err = credentials.NewClientTLSFromFile(testdata.Path("ca.pem"), sn)
if err != nil {
grpclog.Fatalf("Failed to create TLS credentials %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions test/end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func (te *test) startServer(ts testpb.TestServiceServer) {
}
switch te.e.security {
case "tls":
creds, err := credentials.NewServerTLSFromFile(testdata.Path("testdata/server1.pem"), testdata.Path("testdata/server1.key"))
creds, err := credentials.NewServerTLSFromFile(testdata.Path("server1.pem"), testdata.Path("server1.key"))
if err != nil {
te.t.Fatalf("Failed to generate credentials %v", err)
}
Expand Down Expand Up @@ -604,7 +604,7 @@ func (te *test) clientConn() *grpc.ClientConn {
}
switch te.e.security {
case "tls":
creds, err := credentials.NewClientTLSFromFile(testdata.Path("testdata/ca.pem"), "x.test.youtube.com")
creds, err := credentials.NewClientTLSFromFile(testdata.Path("ca.pem"), "x.test.youtube.com")
if err != nil {
te.t.Fatalf("Failed to load credentials: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions testdata/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ import (
)

// Path returns the absolute path the given relative file or directory path,
// relative to the google.golang.org/grpc directory in the user's GOPATH.
// relative to the google.golang.org/grpc/testdata directory in the user's GOPATH.
// If rel is already absolute, it is returned unmodified.
func Path(rel string) string {
if filepath.IsAbs(rel) {
return rel
}

v, err := goPackagePath("google.golang.org/grpc")
v, err := goPackagePath("google.golang.org/grpc/testdata")
if err != nil {
log.Fatalf("Error finding google.golang.org/grpc directory: %v", err)
log.Fatalf("Error finding google.golang.org/grpc/testdata directory: %v", err)
}

return filepath.Join(v, rel)
Expand Down

0 comments on commit ebe3a48

Please sign in to comment.