Merge pull request #4938 from MichaelEischer/bump-go-version
Bump go version to 1.21
This commit is contained in:
commit
3f5e2160de
25 changed files with 175 additions and 204 deletions
21
internal/backend/cache/file_test.go
vendored
21
internal/backend/cache/file_test.go
vendored
|
@ -19,10 +19,10 @@ import (
|
|||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func generateRandomFiles(t testing.TB, tpe backend.FileType, c *Cache) restic.IDSet {
|
||||
func generateRandomFiles(t testing.TB, random *rand.Rand, tpe backend.FileType, c *Cache) restic.IDSet {
|
||||
ids := restic.NewIDSet()
|
||||
for i := 0; i < rand.Intn(15)+10; i++ {
|
||||
buf := rtest.Random(rand.Int(), 1<<19)
|
||||
for i := 0; i < random.Intn(15)+10; i++ {
|
||||
buf := rtest.Random(random.Int(), 1<<19)
|
||||
id := restic.Hash(buf)
|
||||
h := backend.Handle{Type: tpe, Name: id.String()}
|
||||
|
||||
|
@ -88,7 +88,7 @@ func clearFiles(t testing.TB, c *Cache, tpe restic.FileType, valid restic.IDSet)
|
|||
func TestFiles(t *testing.T) {
|
||||
seed := time.Now().Unix()
|
||||
t.Logf("seed is %v", seed)
|
||||
rand.Seed(seed)
|
||||
random := rand.New(rand.NewSource(seed))
|
||||
|
||||
c := TestNewCache(t)
|
||||
|
||||
|
@ -100,7 +100,7 @@ func TestFiles(t *testing.T) {
|
|||
|
||||
for _, tpe := range tests {
|
||||
t.Run(tpe.String(), func(t *testing.T) {
|
||||
ids := generateRandomFiles(t, tpe, c)
|
||||
ids := generateRandomFiles(t, random, tpe, c)
|
||||
id := randomID(ids)
|
||||
|
||||
h := backend.Handle{Type: tpe, Name: id.String()}
|
||||
|
@ -140,12 +140,12 @@ func TestFiles(t *testing.T) {
|
|||
func TestFileLoad(t *testing.T) {
|
||||
seed := time.Now().Unix()
|
||||
t.Logf("seed is %v", seed)
|
||||
rand.Seed(seed)
|
||||
random := rand.New(rand.NewSource(seed))
|
||||
|
||||
c := TestNewCache(t)
|
||||
|
||||
// save about 5 MiB of data in the cache
|
||||
data := rtest.Random(rand.Int(), 5234142)
|
||||
data := rtest.Random(random.Int(), 5234142)
|
||||
id := restic.ID{}
|
||||
copy(id[:], data)
|
||||
h := backend.Handle{
|
||||
|
@ -223,6 +223,10 @@ func TestFileSaveConcurrent(t *testing.T) {
|
|||
t.Skip("may not work due to FILE_SHARE_DELETE issue")
|
||||
}
|
||||
|
||||
seed := time.Now().Unix()
|
||||
t.Logf("seed is %v", seed)
|
||||
random := rand.New(rand.NewSource(seed))
|
||||
|
||||
const nproc = 40
|
||||
|
||||
var (
|
||||
|
@ -231,7 +235,8 @@ func TestFileSaveConcurrent(t *testing.T) {
|
|||
g errgroup.Group
|
||||
id restic.ID
|
||||
)
|
||||
rand.Read(id[:])
|
||||
|
||||
random.Read(id[:])
|
||||
|
||||
h := backend.Handle{
|
||||
Type: restic.PackFile,
|
||||
|
|
|
@ -94,7 +94,7 @@ func run(command string, args ...string) (*StdioConn, *sync.WaitGroup, chan stru
|
|||
err = errW
|
||||
}
|
||||
if err != nil {
|
||||
if util.IsErrDot(err) {
|
||||
if errors.Is(err, exec.ErrDot) {
|
||||
return nil, nil, nil, nil, errors.Errorf("cannot implicitly run relative executable %v found in current directory, use -o rclone.program=./<program> to override", cmd.Path)
|
||||
}
|
||||
return nil, nil, nil, nil, err
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
//go:build go1.20
|
||||
// +build go1.20
|
||||
|
||||
package rest_test
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//go:build !windows && go1.20
|
||||
// +build !windows,go1.20
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package rest_test
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ func startClient(cfg Config) (*SFTP, error) {
|
|||
|
||||
bg, err := util.StartForeground(cmd)
|
||||
if err != nil {
|
||||
if util.IsErrDot(err) {
|
||||
if errors.Is(err, exec.ErrDot) {
|
||||
return nil, errors.Errorf("cannot implicitly run relative executable %v found in current directory, use -o sftp.command=./<command> to override", cmd.Path)
|
||||
}
|
||||
return nil, err
|
||||
|
|
|
@ -3,6 +3,7 @@ package test
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
|
@ -12,7 +13,6 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/minio/sha256-simd"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
|
||||
|
@ -21,10 +21,11 @@ import (
|
|||
"github.com/restic/restic/internal/backend"
|
||||
)
|
||||
|
||||
func seedRand(t testing.TB) {
|
||||
func seedRand(t testing.TB) *rand.Rand {
|
||||
seed := time.Now().UnixNano()
|
||||
rand.Seed(seed)
|
||||
random := rand.New(rand.NewSource(seed))
|
||||
t.Logf("rand initialized with seed %d", seed)
|
||||
return random
|
||||
}
|
||||
|
||||
func beTest(ctx context.Context, be backend.Backend, h backend.Handle) (bool, error) {
|
||||
|
@ -128,7 +129,7 @@ func (s *Suite[C]) TestConfig(t *testing.T) {
|
|||
|
||||
// TestLoad tests the backend's Load function.
|
||||
func (s *Suite[C]) TestLoad(t *testing.T) {
|
||||
seedRand(t)
|
||||
random := seedRand(t)
|
||||
|
||||
b := s.open(t)
|
||||
defer s.close(t, b)
|
||||
|
@ -140,7 +141,7 @@ func (s *Suite[C]) TestLoad(t *testing.T) {
|
|||
test.Assert(t, b.IsNotExist(err), "IsNotExist() did not recognize non-existing blob: %v", err)
|
||||
test.Assert(t, b.IsPermanentError(err), "IsPermanentError() did not recognize non-existing blob: %v", err)
|
||||
|
||||
length := rand.Intn(1<<24) + 2000
|
||||
length := random.Intn(1<<24) + 2000
|
||||
|
||||
data := test.Random(23, length)
|
||||
id := restic.Hash(data)
|
||||
|
@ -173,8 +174,8 @@ func (s *Suite[C]) TestLoad(t *testing.T) {
|
|||
}
|
||||
|
||||
for i := 0; i < loadTests; i++ {
|
||||
l := rand.Intn(length + 2000)
|
||||
o := rand.Intn(length + 2000)
|
||||
l := random.Intn(length + 2000)
|
||||
o := random.Intn(length + 2000)
|
||||
|
||||
d := data
|
||||
if o < len(d) {
|
||||
|
@ -186,7 +187,7 @@ func (s *Suite[C]) TestLoad(t *testing.T) {
|
|||
|
||||
getlen := l
|
||||
if l >= len(d) {
|
||||
if rand.Float32() >= 0.5 {
|
||||
if random.Float32() >= 0.5 {
|
||||
getlen = 0
|
||||
} else {
|
||||
getlen = len(d)
|
||||
|
@ -254,9 +255,9 @@ type setter interface {
|
|||
|
||||
// TestList makes sure that the backend implements List() pagination correctly.
|
||||
func (s *Suite[C]) TestList(t *testing.T) {
|
||||
seedRand(t)
|
||||
random := seedRand(t)
|
||||
|
||||
numTestFiles := rand.Intn(20) + 20
|
||||
numTestFiles := random.Intn(20) + 20
|
||||
|
||||
b := s.open(t)
|
||||
defer s.close(t, b)
|
||||
|
@ -277,7 +278,7 @@ func (s *Suite[C]) TestList(t *testing.T) {
|
|||
list1 := make(map[restic.ID]int64)
|
||||
|
||||
for i := 0; i < numTestFiles; i++ {
|
||||
data := test.Random(rand.Int(), rand.Intn(100)+55)
|
||||
data := test.Random(random.Int(), random.Intn(100)+55)
|
||||
id := restic.Hash(data)
|
||||
h := backend.Handle{Type: backend.PackFile, Name: id.String()}
|
||||
err := b.Save(context.TODO(), h, backend.NewByteReader(data, b.Hasher()))
|
||||
|
@ -353,8 +354,6 @@ func (s *Suite[C]) TestList(t *testing.T) {
|
|||
|
||||
// TestListCancel tests that the context is respected and the error is returned by List.
|
||||
func (s *Suite[C]) TestListCancel(t *testing.T) {
|
||||
seedRand(t)
|
||||
|
||||
numTestFiles := 5
|
||||
|
||||
b := s.open(t)
|
||||
|
@ -498,7 +497,7 @@ func (ec errorCloser) Rewind() error {
|
|||
|
||||
// TestSave tests saving data in the backend.
|
||||
func (s *Suite[C]) TestSave(t *testing.T) {
|
||||
seedRand(t)
|
||||
random := seedRand(t)
|
||||
|
||||
b := s.open(t)
|
||||
defer s.close(t, b)
|
||||
|
@ -510,7 +509,7 @@ func (s *Suite[C]) TestSave(t *testing.T) {
|
|||
}
|
||||
|
||||
for i := 0; i < saveTests; i++ {
|
||||
length := rand.Intn(1<<23) + 200000
|
||||
length := random.Intn(1<<23) + 200000
|
||||
data := test.Random(23, length)
|
||||
id = sha256.Sum256(data)
|
||||
|
||||
|
@ -554,7 +553,7 @@ func (s *Suite[C]) TestSave(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
length := rand.Intn(1<<23) + 200000
|
||||
length := random.Intn(1<<23) + 200000
|
||||
data := test.Random(23, length)
|
||||
id = sha256.Sum256(data)
|
||||
|
||||
|
@ -614,7 +613,7 @@ func (r *incompleteByteReader) Length() int64 {
|
|||
|
||||
// TestSaveError tests saving data in the backend.
|
||||
func (s *Suite[C]) TestSaveError(t *testing.T) {
|
||||
seedRand(t)
|
||||
random := seedRand(t)
|
||||
|
||||
b := s.open(t)
|
||||
defer func() {
|
||||
|
@ -623,7 +622,7 @@ func (s *Suite[C]) TestSaveError(t *testing.T) {
|
|||
_ = b.Close()
|
||||
}()
|
||||
|
||||
length := rand.Intn(1<<23) + 200000
|
||||
length := random.Intn(1<<23) + 200000
|
||||
data := test.Random(24, length)
|
||||
var id restic.ID
|
||||
copy(id[:], data)
|
||||
|
@ -653,7 +652,7 @@ func (b *wrongByteReader) Hash() []byte {
|
|||
|
||||
// TestSaveWrongHash tests that uploads with a wrong hash fail
|
||||
func (s *Suite[C]) TestSaveWrongHash(t *testing.T) {
|
||||
seedRand(t)
|
||||
random := seedRand(t)
|
||||
|
||||
b := s.open(t)
|
||||
defer s.close(t, b)
|
||||
|
@ -662,7 +661,7 @@ func (s *Suite[C]) TestSaveWrongHash(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
length := rand.Intn(1<<23) + 200000
|
||||
length := random.Intn(1<<23) + 200000
|
||||
data := test.Random(25, length)
|
||||
var id restic.ID
|
||||
copy(id[:], data)
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
//go:build go1.19
|
||||
// +build go1.19
|
||||
|
||||
// This file provides a function to check whether an error from cmd.Start() is
|
||||
// exec.ErrDot which was introduced in Go 1.19.
|
||||
// This function is needed so that we can perform this check only for Go 1.19 and
|
||||
// up, whereas for older versions we use a dummy/stub in the file errdot_old.go.
|
||||
// Once the minimum Go version restic supports is 1.19, remove this file and
|
||||
// replace any calls to it with the corresponding code as per below.
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func IsErrDot(err error) bool {
|
||||
return errors.Is(err, exec.ErrDot)
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
//go:build !go1.19
|
||||
// +build !go1.19
|
||||
|
||||
// This file provides a stub for IsErrDot() for Go versions below 1.19.
|
||||
// See the corresponding file errdot_119.go for more information.
|
||||
// Once the minimum Go version restic supports is 1.19, remove this file
|
||||
// and perform the actions listed in errdot_119.go.
|
||||
|
||||
package util
|
||||
|
||||
func IsErrDot(err error) bool {
|
||||
return false
|
||||
}
|
|
@ -11,6 +11,9 @@ import (
|
|||
// to the previous process group.
|
||||
//
|
||||
// The command's environment has all RESTIC_* variables removed.
|
||||
//
|
||||
// Return exec.ErrDot if it would implicitly run an executable from the current
|
||||
// directory.
|
||||
func StartForeground(cmd *exec.Cmd) (bg func() error, err error) {
|
||||
env := os.Environ() // Returns a copy that we can modify.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue