|
@@ -32,15 +32,21 @@ func init() { auth.BcryptCost = bcrypt.MinCost }
|
|
|
|
|
|
|
|
// TestMain sets up an etcd cluster if running the examples.
|
|
// TestMain sets up an etcd cluster if running the examples.
|
|
|
func TestMain(m *testing.M) {
|
|
func TestMain(m *testing.M) {
|
|
|
- useCluster := true // default to running all tests
|
|
|
|
|
|
|
+ useCluster, hasRunArg := false, false // default to running only Test*
|
|
|
for _, arg := range os.Args {
|
|
for _, arg := range os.Args {
|
|
|
if strings.HasPrefix(arg, "-test.run=") {
|
|
if strings.HasPrefix(arg, "-test.run=") {
|
|
|
exp := strings.Split(arg, "=")[1]
|
|
exp := strings.Split(arg, "=")[1]
|
|
|
match, err := regexp.MatchString(exp, "Example")
|
|
match, err := regexp.MatchString(exp, "Example")
|
|
|
useCluster = (err == nil && match) || strings.Contains(exp, "Example")
|
|
useCluster = (err == nil && match) || strings.Contains(exp, "Example")
|
|
|
|
|
+ hasRunArg = true
|
|
|
break
|
|
break
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if !hasRunArg {
|
|
|
|
|
+ // force only running Test* if no args given to avoid leak false
|
|
|
|
|
+ // positives from having a long-running cluster for the examples.
|
|
|
|
|
+ os.Args = append(os.Args, "-test.run=Test")
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
v := 0
|
|
v := 0
|
|
|
if useCluster {
|
|
if useCluster {
|