2013-12-03 07:53:16 +04:00
|
|
|
// 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.
|
|
|
|
|
2014-09-25 01:35:23 +04:00
|
|
|
// Package testfiles locates test files within the Vitess directory tree.
|
2013-12-03 07:53:16 +04:00
|
|
|
package testfiles
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path"
|
2014-03-19 07:39:24 +04:00
|
|
|
"path/filepath"
|
2013-12-03 07:53:16 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2014-03-19 07:39:24 +04:00
|
|
|
|
|
|
|
func Glob(pattern string) []string {
|
|
|
|
vtroot := os.Getenv("VTROOT")
|
|
|
|
if vtroot == "" {
|
|
|
|
panic(fmt.Errorf("VTROOT is not set"))
|
|
|
|
}
|
2015-05-05 20:50:23 +03:00
|
|
|
dir := path.Join(vtroot, "data", "test")
|
|
|
|
if exists, err := exists(dir); !exists {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
resolved := path.Join(dir, pattern)
|
2014-03-19 07:39:24 +04:00
|
|
|
out, err := filepath.Glob(resolved)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
2015-05-05 20:50:23 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|