forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locate.go
49 lines (44 loc) · 1014 Bytes
/
locate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2013, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package testfiles locates test files within the Vitess directory tree.
package testfiles
import (
"fmt"
"os"
"path"
"path/filepath"
)
func Locate(filename string) string {
vtroot := os.Getenv("VTROOT")
if vtroot == "" {
panic(fmt.Errorf("VTROOT is not set"))
}
return path.Join(vtroot, "data", "test", filename)
}
func Glob(pattern string) []string {
vtroot := os.Getenv("VTROOT")
if vtroot == "" {
panic(fmt.Errorf("VTROOT is not set"))
}
dir := path.Join(vtroot, "data", "test")
if exists, err := exists(dir); !exists {
panic(err)
}
resolved := path.Join(dir, pattern)
out, err := filepath.Glob(resolved)
if err != nil {
panic(err)
}
return out
}
func exists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, err
}
return false, err
}