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

unify testdata to only one dir #1297

Merged
merged 2 commits into from
Jul 25, 2017
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
15 changes: 0 additions & 15 deletions benchmark/server/testdata/ca.pem

This file was deleted.

16 changes: 0 additions & 16 deletions benchmark/server/testdata/server1.key

This file was deleted.

16 changes: 0 additions & 16 deletions benchmark/server/testdata/server1.pem

This file was deleted.

7 changes: 2 additions & 5 deletions benchmark/worker/benchmark_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/grpclog"
)

var (
caFile = "benchmark/server/testdata/ca.pem"
"google.golang.org/grpc/testdata"
)

type lockingHistogram struct {
Expand Down Expand Up @@ -122,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(abs(caFile), 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
9 changes: 2 additions & 7 deletions benchmark/worker/benchmark_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/grpclog"
)

var (
// File path related to google.golang.org/grpc.
certFile = "benchmark/server/testdata/server1.pem"
keyFile = "benchmark/server/testdata/server1.key"
"google.golang.org/grpc/testdata"
)

type benchmarkServer struct {
Expand Down Expand Up @@ -90,7 +85,7 @@ func startBenchmarkServer(config *testpb.ServerConfig, serverPort int) (*benchma

// Set security options.
if config.SecurityParams != nil {
creds, err := credentials.NewServerTLSFromFile(abs(certFile), abs(keyFile))
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
43 changes: 1 addition & 42 deletions benchmark/worker/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,7 @@

package main

import (
"log"
"os"
"path/filepath"
"syscall"
)

// abs returns the absolute path the given relative file or directory path,
// relative to the google.golang.org/grpc directory in the user's GOPATH.
// If rel is already absolute, it is returned unmodified.
func abs(rel string) string {
if filepath.IsAbs(rel) {
return rel
}
v, err := goPackagePath("google.golang.org/grpc")
if err != nil {
log.Fatalf("Error finding google.golang.org/grpc/testdata directory: %v", err)
}
return filepath.Join(v, rel)
}
import "syscall"

func cpuTimeDiff(first *syscall.Rusage, latest *syscall.Rusage) (float64, float64) {
var (
Expand All @@ -52,25 +33,3 @@ func cpuTimeDiff(first *syscall.Rusage, latest *syscall.Rusage) (float64, float6

return uTimeElapsed, sTimeElapsed
}

func goPackagePath(pkg string) (path string, err error) {
gp := os.Getenv("GOPATH")
if gp == "" {
return path, os.ErrNotExist
}
for _, p := range filepath.SplitList(gp) {
dir := filepath.Join(p, "src", filepath.FromSlash(pkg))
fi, err := os.Stat(dir)
if os.IsNotExist(err) {
continue
}
if err != nil {
return "", err
}
if !fi.IsDir() {
continue
}
return dir, nil
}
return path, os.ErrNotExist
}
11 changes: 5 additions & 6 deletions clientconn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ import (
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/naming"
"google.golang.org/grpc/testdata"
)

const tlsDir = "testdata/"

func assertState(wantState ConnectivityState, cc *ClientConn) (ConnectivityState, bool) {
ctx, _ := context.WithTimeout(context.Background(), time.Second)
var state ConnectivityState
Expand Down Expand Up @@ -93,7 +92,7 @@ func TestDialTimeout(t *testing.T) {
}

func TestTLSDialTimeout(t *testing.T) {
creds, err := credentials.NewClientTLSFromFile(tlsDir+"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 @@ -120,7 +119,7 @@ func TestDefaultAuthority(t *testing.T) {

func TestTLSServerNameOverwrite(t *testing.T) {
overwriteServerName := "over.write.server.name"
creds, err := credentials.NewClientTLSFromFile(tlsDir+"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 @@ -148,7 +147,7 @@ func TestWithAuthority(t *testing.T) {

func TestWithAuthorityAndTLS(t *testing.T) {
overwriteServerName := "over.write.server.name"
creds, err := credentials.NewClientTLSFromFile(tlsDir+"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 @@ -219,7 +218,7 @@ func (c securePerRPCCredentials) RequireTransportSecurity() bool {
}

func TestCredentialsMisuse(t *testing.T) {
tlsCreds, err := credentials.NewClientTLSFromFile(tlsDir+"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
7 changes: 3 additions & 4 deletions credentials/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"

"golang.org/x/net/context"
"google.golang.org/grpc/testdata"
)

func TestTLSOverrideServerName(t *testing.T) {
Expand All @@ -50,8 +51,6 @@ func TestTLSClone(t *testing.T) {

}

const tlsDir = "../test/testdata/"

type serverHandshake func(net.Conn) (AuthInfo, error)

func TestClientHandshakeReturnsAuthInfo(t *testing.T) {
Expand Down Expand Up @@ -162,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(tlsDir+"server1.pem", tlsDir+"server1.key")
serverTLS, err := NewServerTLSFromFile(testdata.Path("server1.pem"), testdata.Path("server1.key"))
if err != nil {
return nil, err
}
Expand All @@ -184,7 +183,7 @@ func gRPCClientHandshake(conn net.Conn, lisAddr string) (AuthInfo, error) {
}

func tlsServerHandshake(conn net.Conn) (AuthInfo, error) {
cert, err := tls.LoadX509KeyPair(tlsDir+"server1.pem", tlsDir+"server1.key")
cert, err := tls.LoadX509KeyPair(testdata.Path("server1.pem"), testdata.Path("server1.key"))
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion examples/route_guide/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ import (
"google.golang.org/grpc/credentials"
pb "google.golang.org/grpc/examples/route_guide/routeguide"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/testdata"
)

var (
tls = flag.Bool("tls", false, "Connection uses TLS if true, else plain TCP")
caFile = flag.String("ca_file", "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
5 changes: 3 additions & 2 deletions examples/route_guide/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (

"google.golang.org/grpc/credentials"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/testdata"

"github.com/golang/protobuf/proto"

Expand All @@ -45,8 +46,8 @@ import (

var (
tls = flag.Bool("tls", false, "Connection uses TLS if true, else plain TCP")
certFile = flag.String("cert_file", "testdata/server1.pem", "The TLS cert file")
keyFile = flag.String("key_file", "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
15 changes: 0 additions & 15 deletions examples/route_guide/testdata/ca.pem

This file was deleted.

16 changes: 0 additions & 16 deletions examples/route_guide/testdata/server1.key

This file was deleted.

16 changes: 0 additions & 16 deletions examples/route_guide/testdata/server1.pem

This file was deleted.

6 changes: 2 additions & 4 deletions interop/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/interop"
testpb "google.golang.org/grpc/interop/grpc_testing"
"google.golang.org/grpc/testdata"
)

var (
Expand Down Expand Up @@ -60,9 +61,6 @@ var (
custom_metadata: server will echo custom metadata;
unimplemented_method: client attempts to call unimplemented method;
unimplemented_service: client attempts to call unimplemented service.`)

// The test CA root cert file
testCAFile = "testdata/ca.pem"
)

func main() {
Expand All @@ -77,7 +75,7 @@ func main() {
var creds credentials.TransportCredentials
if *testCA {
var err error
creds, err = credentials.NewClientTLSFromFile(testCAFile, sn)
creds, err = credentials.NewClientTLSFromFile(testdata.Path("ca.pem"), sn)
if err != nil {
grpclog.Fatalf("Failed to create TLS credentials %v", err)
}
Expand Down
15 changes: 0 additions & 15 deletions interop/client/testdata/ca.pem

This file was deleted.

16 changes: 0 additions & 16 deletions interop/client/testdata/server1.key

This file was deleted.

16 changes: 0 additions & 16 deletions interop/client/testdata/server1.pem

This file was deleted.

Loading