Merge pull request #4070 from restic/fix-cloud-tests

Fix cloud tests
This commit is contained in:
Michael Eischer 2022-12-03 19:21:25 +01:00 committed by GitHub
commit 223da7344e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 12 deletions

View File

@ -8,7 +8,6 @@ import (
"hash"
"io"
"net/http"
"os"
"path"
"strings"
@ -130,7 +129,8 @@ func (be *Backend) SetListMaxItems(i int) {
// IsNotExist returns true if the error is caused by a not existing file.
func (be *Backend) IsNotExist(err error) bool {
debug.Log("IsNotExist(%T, %#v)", err, err)
return os.IsNotExist(err)
var aerr storage.AzureStorageServiceError
return errors.As(err, &aerr) && aerr.StatusCode == http.StatusNotFound
}
// Join combines path components with slashes.

View File

@ -170,13 +170,7 @@ func (be *Backend) SetListMaxItems(i int) {
// IsNotExist returns true if the error is caused by a not existing file.
func (be *Backend) IsNotExist(err error) bool {
debug.Log("IsNotExist(%T, %#v)", err, err)
if os.IsNotExist(err) {
return true
}
var gerr *googleapi.Error
return errors.As(err, &gerr) && gerr.Code == 404
return errors.Is(err, storage.ErrObjectNotExist)
}
// Join combines path components with slashes.

View File

@ -170,9 +170,6 @@ func isAccessDenied(err error) bool {
// IsNotExist returns true if the error is caused by a not existing file.
func (be *Backend) IsNotExist(err error) bool {
debug.Log("IsNotExist(%T, %#v)", err, err)
if errors.Is(err, os.ErrNotExist) {
return true
}
var e minio.ErrorResponse
return errors.As(err, &e) && e.Code == "NoSuchKey"

View File

@ -92,6 +92,7 @@ func (s *Suite) TestConfig(t *testing.T) {
if err == nil {
t.Fatalf("did not get expected error for non-existing config")
}
test.Assert(t, b.IsNotExist(err), "IsNotExist() did not recognize error from LoadAll(): %v", err)
err = b.Save(context.TODO(), restic.Handle{Type: restic.ConfigFile}, restic.NewByteReader([]byte(testString), b.Hasher()))
if err != nil {
@ -131,11 +132,13 @@ func (s *Suite) TestLoad(t *testing.T) {
if err == nil {
t.Fatalf("Load() did not return an error for invalid handle")
}
test.Assert(t, !b.IsNotExist(err), "IsNotExist() should not accept an invalid handle error: %v", err)
err = testLoad(b, restic.Handle{Type: restic.PackFile, Name: "foobar"}, 0, 0)
if err == nil {
t.Fatalf("Load() did not return an error for non-existing blob")
}
test.Assert(t, b.IsNotExist(err), "IsNotExist() did not recognize non-existing blob: %v", err)
length := rand.Intn(1<<24) + 2000
@ -762,6 +765,8 @@ func (s *Suite) TestBackend(t *testing.T) {
b := s.open(t)
defer s.close(t, b)
test.Assert(t, !b.IsNotExist(nil), "IsNotExist() recognized nil error")
for _, tpe := range []restic.FileType{
restic.PackFile, restic.KeyFile, restic.LockFile,
restic.SnapshotFile, restic.IndexFile,
@ -780,10 +785,12 @@ func (s *Suite) TestBackend(t *testing.T) {
// try to stat a not existing blob
_, err = b.Stat(context.TODO(), h)
test.Assert(t, err != nil, "blob data could be extracted before creation")
test.Assert(t, b.IsNotExist(err), "IsNotExist() did not recognize Stat() error: %v", err)
// try to read not existing blob
err = testLoad(b, h, 0, 0)
test.Assert(t, err != nil, "blob could be read before creation")
test.Assert(t, b.IsNotExist(err), "IsNotExist() did not recognize Load() error: %v", err)
// try to get string out, should fail
ret, err = beTest(context.TODO(), b, h)