mirror of
https://github.com/rclone/rclone.git
synced 2025-02-12 16:40:14 +01:00
lib/bucket: add IsAllSlashes function
This commit is contained in:
parent
8e955c6b13
commit
b4990cd858
@ -42,6 +42,21 @@ func Join(path1, path2 string) string {
|
|||||||
return strings.TrimSuffix(path1, "/") + "/" + strings.TrimPrefix(path2, "/")
|
return strings.TrimSuffix(path1, "/") + "/" + strings.TrimPrefix(path2, "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsAllSlashes returns true if s is all / characters.
|
||||||
|
//
|
||||||
|
// It returns false if s is "".
|
||||||
|
func IsAllSlashes(s string) bool {
|
||||||
|
if len(s) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, c := range s {
|
||||||
|
if c != '/' {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// Cache stores whether buckets are available and their IDs
|
// Cache stores whether buckets are available and their IDs
|
||||||
type Cache struct {
|
type Cache struct {
|
||||||
mu sync.Mutex // mutex to protect created and deleted
|
mu sync.Mutex // mutex to protect created and deleted
|
||||||
|
@ -45,6 +45,24 @@ func TestJoin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsAllSlashes(t *testing.T) {
|
||||||
|
for _, test := range []struct {
|
||||||
|
in string
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{in: "", want: false},
|
||||||
|
{in: "/", want: true},
|
||||||
|
{in: "x/", want: false},
|
||||||
|
{in: "/x", want: false},
|
||||||
|
{in: "//", want: true},
|
||||||
|
{in: "/x/", want: false},
|
||||||
|
{in: "///", want: true},
|
||||||
|
} {
|
||||||
|
got := IsAllSlashes(test.in)
|
||||||
|
assert.Equal(t, test.want, got, test.in)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCache(t *testing.T) {
|
func TestCache(t *testing.T) {
|
||||||
c := NewCache()
|
c := NewCache()
|
||||||
errBoom := errors.New("boom")
|
errBoom := errors.New("boom")
|
||||||
|
Loading…
Reference in New Issue
Block a user