mirror of
https://github.com/rclone/rclone
synced 2024-12-22 13:03:02 +01:00
Prefix all test remotes with rclone-test-
and make names more pronouncable
This commit is contained in:
parent
18ebec8276
commit
109d4ee490
@ -10,13 +10,13 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ncw/rclone/fs"
|
"github.com/ncw/rclone/fs"
|
||||||
_ "github.com/ncw/rclone/fs/all" // import all fs
|
_ "github.com/ncw/rclone/fs/all" // import all fs
|
||||||
|
"github.com/ncw/rclone/fstest"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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
|
// cleanFs runs a single clean fs for left over directories
|
||||||
func (t *test) cleanFs() error {
|
func (t *test) cleanFs() error {
|
||||||
f, err := fs.NewFs(t.remote)
|
f, err := fs.NewFs(t.remote)
|
||||||
@ -97,8 +90,7 @@ func (t *test) cleanFs() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for dir := range f.ListDir() {
|
for dir := range f.ListDir() {
|
||||||
insideDigits := len(findInteriorDigits.FindAllString(dir.Name, -1))
|
if fstest.MatchTestRemote.MatchString(dir.Name) {
|
||||||
if matchTestRemote.MatchString(dir.Name) && insideDigits >= 2 {
|
|
||||||
log.Printf("Purging %s%s", t.remote, dir.Name)
|
log.Printf("Purging %s%s", t.remote, dir.Name)
|
||||||
dir, err := fs.NewFs(t.remote + dir.Name)
|
dir, err := fs.NewFs(t.remote + dir.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -18,6 +19,11 @@ import (
|
|||||||
"github.com/ncw/rclone/fs"
|
"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
|
// Seed the random number generator
|
||||||
func init() {
|
func init() {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
@ -206,9 +212,17 @@ func Time(timeString string) time.Time {
|
|||||||
|
|
||||||
// RandomString create a random string for test purposes
|
// RandomString create a random string for test purposes
|
||||||
func RandomString(n int) string {
|
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)
|
out := make([]byte, n)
|
||||||
|
p := 0
|
||||||
for i := range out {
|
for i := range out {
|
||||||
|
source := pattern[p]
|
||||||
|
p = (p + 1) % len(pattern)
|
||||||
out[i] = source[rand.Intn(len(source))]
|
out[i] = source[rand.Intn(len(source))]
|
||||||
}
|
}
|
||||||
return string(out)
|
return string(out)
|
||||||
@ -242,7 +256,10 @@ func RandomRemoteName(remoteName string) (string, string, error) {
|
|||||||
if !strings.HasSuffix(remoteName, ":") {
|
if !strings.HasSuffix(remoteName, ":") {
|
||||||
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
|
remoteName += leafName
|
||||||
}
|
}
|
||||||
return remoteName, leafName, nil
|
return remoteName, leafName, nil
|
||||||
@ -266,7 +283,7 @@ func RandomRemote(remoteName string, subdir bool) (fs.Fs, func(), error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
remoteName += "/" + RandomString(8)
|
remoteName += "/rclone-test-subdir-" + RandomString(8)
|
||||||
}
|
}
|
||||||
|
|
||||||
remote, err := fs.NewFs(remoteName)
|
remote, err := fs.NewFs(remoteName)
|
||||||
|
Loading…
Reference in New Issue
Block a user