2020-06-18 11:54:54 +00:00
|
|
|
package rclone
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-07-26 10:06:18 +00:00
|
|
|
"os/exec"
|
2020-06-18 11:54:54 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-07-26 10:06:18 +00:00
|
|
|
"github.com/restic/restic/internal/errors"
|
2020-06-18 11:54:54 +00:00
|
|
|
"github.com/restic/restic/internal/restic"
|
|
|
|
rtest "github.com/restic/restic/internal/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
// restic should detect rclone exiting.
|
|
|
|
func TestRcloneExit(t *testing.T) {
|
2022-12-09 12:42:33 +00:00
|
|
|
dir := rtest.TempDir(t)
|
2020-06-18 11:54:54 +00:00
|
|
|
cfg := NewConfig()
|
|
|
|
cfg.Remote = dir
|
2023-06-08 11:11:34 +00:00
|
|
|
be, err := Open(context.TODO(), cfg, nil)
|
2022-06-13 18:35:37 +00:00
|
|
|
var e *exec.Error
|
|
|
|
if errors.As(err, &e) && e.Err == exec.ErrNotFound {
|
2020-07-26 10:06:18 +00:00
|
|
|
t.Skipf("program %q not found", e.Name)
|
|
|
|
return
|
|
|
|
}
|
2020-06-18 11:54:54 +00:00
|
|
|
rtest.OK(t, err)
|
2021-01-30 15:46:34 +00:00
|
|
|
defer func() {
|
2021-01-30 17:49:30 +00:00
|
|
|
// ignore the error as the test will kill rclone (see below)
|
|
|
|
_ = be.Close()
|
2021-01-30 15:46:34 +00:00
|
|
|
}()
|
2020-06-18 11:54:54 +00:00
|
|
|
|
|
|
|
err = be.cmd.Process.Kill()
|
|
|
|
rtest.OK(t, err)
|
|
|
|
t.Log("killed rclone")
|
|
|
|
|
2020-08-01 10:06:30 +00:00
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
_, err = be.Stat(context.TODO(), restic.Handle{
|
|
|
|
Name: "foo",
|
2020-08-16 09:16:38 +00:00
|
|
|
Type: restic.PackFile,
|
2020-08-01 10:06:30 +00:00
|
|
|
})
|
|
|
|
rtest.Assert(t, err != nil, "expected an error")
|
|
|
|
}
|
2020-06-18 11:54:54 +00:00
|
|
|
}
|
2022-09-22 19:52:18 +00:00
|
|
|
|
|
|
|
// restic should detect rclone startup failures
|
|
|
|
func TestRcloneFailedStart(t *testing.T) {
|
|
|
|
cfg := NewConfig()
|
|
|
|
// exits with exit code 1
|
|
|
|
cfg.Program = "false"
|
2023-06-08 11:11:34 +00:00
|
|
|
_, err := Open(context.TODO(), cfg, nil)
|
2022-09-22 19:52:18 +00:00
|
|
|
var e *exec.ExitError
|
|
|
|
if !errors.As(err, &e) {
|
|
|
|
// unexpected error
|
|
|
|
rtest.OK(t, err)
|
|
|
|
}
|
|
|
|
}
|