mirror of
https://github.com/restic/restic.git
synced 2025-03-16 00:00:05 +01:00
Generate a random bucket name for backend/b2 e2e tests.
This commit is contained in:
parent
591f51c72e
commit
affa1dd0a0
1 changed files with 20 additions and 4 deletions
|
@ -1,13 +1,15 @@
|
|||
package b2_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"math/rand"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"restic"
|
||||
|
||||
"restic/errors"
|
||||
|
||||
"restic/backend/b2"
|
||||
"restic/backend/test"
|
||||
"restic/errors"
|
||||
)
|
||||
|
||||
//go:generate go run ../test/generate_backend_tests.go
|
||||
|
@ -21,7 +23,7 @@ func init() {
|
|||
cfg := b2.Config{
|
||||
AccountID: os.Getenv("B2_ACCOUNT_ID"),
|
||||
Key: os.Getenv("B2_ACCOUNT_KEY"),
|
||||
Bucket: "restic-test",
|
||||
Bucket: generateBucketName(),
|
||||
Prefix: "test",
|
||||
}
|
||||
|
||||
|
@ -58,3 +60,17 @@ func init() {
|
|||
// return err
|
||||
// }
|
||||
}
|
||||
|
||||
// Generates a random bucket name starting with "restic-test-".
|
||||
func generateBucketName() string {
|
||||
const chars = "abcdefghijklmnopqrstuvwxyz0123456789"
|
||||
const lenChars = len(chars)
|
||||
const lenBucket = 16
|
||||
var bucket bytes.Buffer
|
||||
bucket.WriteString("restic-test-")
|
||||
r := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
|
||||
for i := 0; i < lenBucket; i++ {
|
||||
bucket.WriteByte(chars[r.Intn(lenChars)])
|
||||
}
|
||||
return bucket.String()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue