1
mirror of https://github.com/rclone/rclone synced 2024-12-21 11:45:56 +01:00

Prefix all test remotes with rclone-test- and make names more pronouncable

This commit is contained in:
Nick Craig-Wood 2016-01-24 12:37:46 +00:00
parent 18ebec8276
commit 109d4ee490
2 changed files with 22 additions and 13 deletions

View File

@ -10,13 +10,13 @@ import (
"log"
"os"
"os/exec"
"regexp"
"runtime"
"strings"
"time"
"github.com/ncw/rclone/fs"
_ "github.com/ncw/rclone/fs/all" // import all fs
"github.com/ncw/rclone/fstest"
)
var (
@ -83,13 +83,6 @@ func (t *test) trial() {
}
}
var (
// matchTestRemote matches the remote names used for testing
matchTestRemote = regexp.MustCompile(`^[abcdefghijklmnopqrstuvwxyz0123456789]{32}$`)
// findInteriorDigits makes sure there are digits inside the string
findInteriorDigits = regexp.MustCompile(`[a-z][0-9]+[a-z]`)
)
// cleanFs runs a single clean fs for left over directories
func (t *test) cleanFs() error {
f, err := fs.NewFs(t.remote)
@ -97,8 +90,7 @@ func (t *test) cleanFs() error {
return err
}
for dir := range f.ListDir() {
insideDigits := len(findInteriorDigits.FindAllString(dir.Name, -1))
if matchTestRemote.MatchString(dir.Name) && insideDigits >= 2 {
if fstest.MatchTestRemote.MatchString(dir.Name) {
log.Printf("Purging %s%s", t.remote, dir.Name)
dir, err := fs.NewFs(t.remote + dir.Name)
if err != nil {

View File

@ -11,6 +11,7 @@ import (
"math/rand"
"os"
"path/filepath"
"regexp"
"strings"
"testing"
"time"
@ -18,6 +19,11 @@ import (
"github.com/ncw/rclone/fs"
)
var (
// MatchTestRemote matches the remote names used for testing
MatchTestRemote = regexp.MustCompile(`^rclone-test-[abcdefghijklmnopqrstuvwxyz0123456789]{24}$`)
)
// Seed the random number generator
func init() {
rand.Seed(time.Now().UnixNano())
@ -206,9 +212,17 @@ func Time(timeString string) time.Time {
// RandomString create a random string for test purposes
func RandomString(n int) string {
source := "abcdefghijklmnopqrstuvwxyz0123456789"
const (
vowel = "aeiou"
consonant = "bcdfghjklmnpqrstvwxyz"
digit = "0123456789"
)
pattern := []string{consonant, vowel, consonant, vowel, consonant, vowel, consonant, digit}
out := make([]byte, n)
p := 0
for i := range out {
source := pattern[p]
p = (p + 1) % len(pattern)
out[i] = source[rand.Intn(len(source))]
}
return string(out)
@ -242,7 +256,10 @@ func RandomRemoteName(remoteName string) (string, string, error) {
if !strings.HasSuffix(remoteName, ":") {
remoteName += "/"
}
leafName = RandomString(32)
leafName = "rclone-test-" + RandomString(24)
if !MatchTestRemote.MatchString(leafName) {
log.Fatalf("%q didn't match the test remote name regexp", leafName)
}
remoteName += leafName
}
return remoteName, leafName, nil
@ -266,7 +283,7 @@ func RandomRemote(remoteName string, subdir bool) (fs.Fs, func(), error) {
if err != nil {
return nil, nil, err
}
remoteName += "/" + RandomString(8)
remoteName += "/rclone-test-subdir-" + RandomString(8)
}
remote, err := fs.NewFs(remoteName)