2 * Copyright 2017 gRPC authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
26 // Path returns the absolute path the given relative file or directory path,
27 // relative to the google.golang.org/grpc/testdata directory in the user's GOPATH.
28 // If rel is already absolute, it is returned unmodified.
29 func Path(rel string) string {
30 if filepath.IsAbs(rel) {
34 v, err := goPackagePath("google.golang.org/grpc/testdata")
36 log.Fatalf("Error finding google.golang.org/grpc/testdata directory: %v", err)
39 return filepath.Join(v, rel)
42 func goPackagePath(pkg string) (path string, err error) {
43 gp := os.Getenv("GOPATH")
45 return path, os.ErrNotExist
48 for _, p := range filepath.SplitList(gp) {
49 dir := filepath.Join(p, "src", filepath.FromSlash(pkg))
50 fi, err := os.Stat(dir)
51 if os.IsNotExist(err) {
62 return path, os.ErrNotExist