summaryrefslogtreecommitdiffhomepage
path: root/runsc
diff options
context:
space:
mode:
authorNicolas Lacasse <nlacasse@google.com>2018-11-19 17:55:42 -0800
committerNicolas Lacasse <nlacasse@google.com>2018-11-20 14:04:41 -0800
commit9363edcf067a69ba443425c0b5604897fcd5b87b (patch)
treedfad23dd590e16a6eb5e6e31212f2b6fa51842bc /runsc
parentfadffa2ff831034ff63146abf408ff71462b9f43 (diff)
Internal change.
PiperOrigin-RevId: 222170431 Change-Id: I26a6d6ad5d6910a94bb8b0a05fc2d12e23098399
Diffstat (limited to 'runsc')
-rw-r--r--runsc/test/testutil/testutil.go41
1 files changed, 27 insertions, 14 deletions
diff --git a/runsc/test/testutil/testutil.go b/runsc/test/testutil/testutil.go
index 7a17d0552..162ffe09f 100644
--- a/runsc/test/testutil/testutil.go
+++ b/runsc/test/testutil/testutil.go
@@ -87,22 +87,35 @@ func FindFile(path string) (string, error) {
root = dir[:len(dir)-1]
}
- // bazel adds the build type to the directory structure. Since I don't want
- // to guess what build type it's, just place '*' to match anything.
- //
- // The pattern goes like: /test-path/__main__/directories/*/file.
- pattern := filepath.Join(root, filepath.Dir(path), "*", filepath.Base(path))
- matches, err := filepath.Glob(pattern)
- if err != nil {
- return "", fmt.Errorf("error globbing %q: %v", pattern, err)
- }
- if len(matches) == 0 {
- return "", fmt.Errorf("file %q not found", path)
+ // Annoyingly, bazel adds the build type to the directory path for go
+ // binaries, but not for c++ binaries. We use two different patterns to
+ // to find our file.
+ patterns := []string{
+ // Try the obvious path first.
+ filepath.Join(root, path),
+ // If it was a go binary, use a wildcard to match the build
+ // type. The pattern is: /test-path/__main__/directories/*/file.
+ filepath.Join(root, filepath.Dir(path), "*", filepath.Base(path)),
}
- if len(matches) != 1 {
- return "", fmt.Errorf("more than one match found for %q: %s", path, matches)
+
+ for _, p := range patterns {
+ matches, err := filepath.Glob(p)
+ if err != nil {
+ // "The only possible returned error is ErrBadPattern,
+ // when pattern is malformed." -godoc
+ return "", fmt.Errorf("error globbing %q: %v", p, err)
+ }
+ switch len(matches) {
+ case 0:
+ // Try the next pattern.
+ case 1:
+ // We found it.
+ return matches[0], nil
+ default:
+ return "", fmt.Errorf("more than one match found for %q: %s", path, matches)
+ }
}
- return matches[0], nil
+ return "", fmt.Errorf("file %q not found", path)
}
// TestConfig returns the default configuration to use in tests. Note that