2020-12-16 12:58:02 +00:00
|
|
|
package local
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
2020-11-02 09:34:21 +00:00
|
|
|
"fmt"
|
2020-12-16 12:58:02 +00:00
|
|
|
"os"
|
|
|
|
"syscall"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/restic/restic/internal/restic"
|
|
|
|
rtest "github.com/restic/restic/internal/test"
|
|
|
|
|
|
|
|
"github.com/cenkalti/backoff/v4"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNoSpacePermanent(t *testing.T) {
|
2020-11-02 09:34:21 +00:00
|
|
|
oldTempFile := tempFile
|
2020-12-16 12:58:02 +00:00
|
|
|
defer func() {
|
2020-11-02 09:34:21 +00:00
|
|
|
tempFile = oldTempFile
|
2020-12-16 12:58:02 +00:00
|
|
|
}()
|
|
|
|
|
2020-11-02 09:34:21 +00:00
|
|
|
tempFile = func(_, _ string) (*os.File, error) {
|
|
|
|
return nil, fmt.Errorf("not creating tempfile, %w", syscall.ENOSPC)
|
2020-12-16 12:58:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dir, cleanup := rtest.TempDir(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
be, err := Open(context.Background(), Config{Path: dir})
|
|
|
|
rtest.OK(t, err)
|
2021-01-30 18:35:46 +00:00
|
|
|
defer func() {
|
|
|
|
rtest.OK(t, be.Close())
|
|
|
|
}()
|
2020-12-16 12:58:02 +00:00
|
|
|
|
|
|
|
h := restic.Handle{Type: restic.ConfigFile}
|
|
|
|
err = be.Save(context.Background(), h, nil)
|
|
|
|
_, ok := err.(*backoff.PermanentError)
|
|
|
|
rtest.Assert(t, ok,
|
|
|
|
"error type should be backoff.PermanentError, got %T", err)
|
|
|
|
rtest.Assert(t, errors.Is(err, syscall.ENOSPC),
|
|
|
|
"could not recover original ENOSPC error")
|
|
|
|
}
|