forked from TrueCloudLab/restic
Fix issues reported by staticcheck
This commit is contained in:
parent
a00e27adf6
commit
f867e65bcd
3 changed files with 32 additions and 12 deletions
|
@ -54,7 +54,7 @@ func TestReadRepo(t *testing.T) {
|
||||||
|
|
||||||
var opts3 GlobalOptions
|
var opts3 GlobalOptions
|
||||||
opts3.RepositoryFile = foo + "-invalid"
|
opts3.RepositoryFile = foo + "-invalid"
|
||||||
repo, err = ReadRepo(opts3)
|
_, err = ReadRepo(opts3)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("must not read repository path from invalid file path")
|
t.Fatal("must not read repository path from invalid file path")
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,7 +166,7 @@ func testRunDiffOutput(gopts GlobalOptions, firstSnapshotID string, secondSnapsh
|
||||||
ShowMetadata: false,
|
ShowMetadata: false,
|
||||||
}
|
}
|
||||||
err := runDiff(opts, gopts, []string{firstSnapshotID, secondSnapshotID})
|
err := runDiff(opts, gopts, []string{firstSnapshotID, secondSnapshotID})
|
||||||
return string(buf.Bytes()), err
|
return buf.String(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func testRunRebuildIndex(t testing.TB, gopts GlobalOptions) {
|
func testRunRebuildIndex(t testing.TB, gopts GlobalOptions) {
|
||||||
|
@ -657,7 +657,11 @@ func TestBackupTags(t *testing.T) {
|
||||||
testRunBackup(t, "", []string{env.testdata}, opts, env.gopts)
|
testRunBackup(t, "", []string{env.testdata}, opts, env.gopts)
|
||||||
testRunCheck(t, env.gopts)
|
testRunCheck(t, env.gopts)
|
||||||
newest, _ := testRunSnapshots(t, env.gopts)
|
newest, _ := testRunSnapshots(t, env.gopts)
|
||||||
rtest.Assert(t, newest != nil, "expected a new backup, got nil")
|
|
||||||
|
if newest == nil {
|
||||||
|
t.Fatal("expected a backup, got nil")
|
||||||
|
}
|
||||||
|
|
||||||
rtest.Assert(t, len(newest.Tags) == 0,
|
rtest.Assert(t, len(newest.Tags) == 0,
|
||||||
"expected no tags, got %v", newest.Tags)
|
"expected no tags, got %v", newest.Tags)
|
||||||
parent := newest
|
parent := newest
|
||||||
|
@ -666,7 +670,11 @@ func TestBackupTags(t *testing.T) {
|
||||||
testRunBackup(t, "", []string{env.testdata}, opts, env.gopts)
|
testRunBackup(t, "", []string{env.testdata}, opts, env.gopts)
|
||||||
testRunCheck(t, env.gopts)
|
testRunCheck(t, env.gopts)
|
||||||
newest, _ = testRunSnapshots(t, env.gopts)
|
newest, _ = testRunSnapshots(t, env.gopts)
|
||||||
rtest.Assert(t, newest != nil, "expected a new backup, got nil")
|
|
||||||
|
if newest == nil {
|
||||||
|
t.Fatal("expected a backup, got nil")
|
||||||
|
}
|
||||||
|
|
||||||
rtest.Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "NL",
|
rtest.Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "NL",
|
||||||
"expected one NL tag, got %v", newest.Tags)
|
"expected one NL tag, got %v", newest.Tags)
|
||||||
// Tagged backup should have untagged backup as parent.
|
// Tagged backup should have untagged backup as parent.
|
||||||
|
@ -833,7 +841,10 @@ func TestTag(t *testing.T) {
|
||||||
testRunBackup(t, "", []string{env.testdata}, BackupOptions{}, env.gopts)
|
testRunBackup(t, "", []string{env.testdata}, BackupOptions{}, env.gopts)
|
||||||
testRunCheck(t, env.gopts)
|
testRunCheck(t, env.gopts)
|
||||||
newest, _ := testRunSnapshots(t, env.gopts)
|
newest, _ := testRunSnapshots(t, env.gopts)
|
||||||
rtest.Assert(t, newest != nil, "expected a new backup, got nil")
|
if newest == nil {
|
||||||
|
t.Fatal("expected a new backup, got nil")
|
||||||
|
}
|
||||||
|
|
||||||
rtest.Assert(t, len(newest.Tags) == 0,
|
rtest.Assert(t, len(newest.Tags) == 0,
|
||||||
"expected no tags, got %v", newest.Tags)
|
"expected no tags, got %v", newest.Tags)
|
||||||
rtest.Assert(t, newest.Original == nil,
|
rtest.Assert(t, newest.Original == nil,
|
||||||
|
@ -843,7 +854,9 @@ func TestTag(t *testing.T) {
|
||||||
testRunTag(t, TagOptions{SetTags: restic.TagLists{[]string{"NL"}}}, env.gopts)
|
testRunTag(t, TagOptions{SetTags: restic.TagLists{[]string{"NL"}}}, env.gopts)
|
||||||
testRunCheck(t, env.gopts)
|
testRunCheck(t, env.gopts)
|
||||||
newest, _ = testRunSnapshots(t, env.gopts)
|
newest, _ = testRunSnapshots(t, env.gopts)
|
||||||
rtest.Assert(t, newest != nil, "expected a new backup, got nil")
|
if newest == nil {
|
||||||
|
t.Fatal("expected a backup, got nil")
|
||||||
|
}
|
||||||
rtest.Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "NL",
|
rtest.Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "NL",
|
||||||
"set failed, expected one NL tag, got %v", newest.Tags)
|
"set failed, expected one NL tag, got %v", newest.Tags)
|
||||||
rtest.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
|
rtest.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
|
||||||
|
@ -853,7 +866,9 @@ func TestTag(t *testing.T) {
|
||||||
testRunTag(t, TagOptions{AddTags: restic.TagLists{[]string{"CH"}}}, env.gopts)
|
testRunTag(t, TagOptions{AddTags: restic.TagLists{[]string{"CH"}}}, env.gopts)
|
||||||
testRunCheck(t, env.gopts)
|
testRunCheck(t, env.gopts)
|
||||||
newest, _ = testRunSnapshots(t, env.gopts)
|
newest, _ = testRunSnapshots(t, env.gopts)
|
||||||
rtest.Assert(t, newest != nil, "expected a new backup, got nil")
|
if newest == nil {
|
||||||
|
t.Fatal("expected a backup, got nil")
|
||||||
|
}
|
||||||
rtest.Assert(t, len(newest.Tags) == 2 && newest.Tags[0] == "NL" && newest.Tags[1] == "CH",
|
rtest.Assert(t, len(newest.Tags) == 2 && newest.Tags[0] == "NL" && newest.Tags[1] == "CH",
|
||||||
"add failed, expected CH,NL tags, got %v", newest.Tags)
|
"add failed, expected CH,NL tags, got %v", newest.Tags)
|
||||||
rtest.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
|
rtest.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
|
||||||
|
@ -863,7 +878,9 @@ func TestTag(t *testing.T) {
|
||||||
testRunTag(t, TagOptions{RemoveTags: restic.TagLists{[]string{"NL"}}}, env.gopts)
|
testRunTag(t, TagOptions{RemoveTags: restic.TagLists{[]string{"NL"}}}, env.gopts)
|
||||||
testRunCheck(t, env.gopts)
|
testRunCheck(t, env.gopts)
|
||||||
newest, _ = testRunSnapshots(t, env.gopts)
|
newest, _ = testRunSnapshots(t, env.gopts)
|
||||||
rtest.Assert(t, newest != nil, "expected a new backup, got nil")
|
if newest == nil {
|
||||||
|
t.Fatal("expected a backup, got nil")
|
||||||
|
}
|
||||||
rtest.Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "CH",
|
rtest.Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "CH",
|
||||||
"remove failed, expected one CH tag, got %v", newest.Tags)
|
"remove failed, expected one CH tag, got %v", newest.Tags)
|
||||||
rtest.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
|
rtest.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
|
||||||
|
@ -874,7 +891,9 @@ func TestTag(t *testing.T) {
|
||||||
testRunTag(t, TagOptions{RemoveTags: restic.TagLists{[]string{"CH", "US", "RU"}}}, env.gopts)
|
testRunTag(t, TagOptions{RemoveTags: restic.TagLists{[]string{"CH", "US", "RU"}}}, env.gopts)
|
||||||
testRunCheck(t, env.gopts)
|
testRunCheck(t, env.gopts)
|
||||||
newest, _ = testRunSnapshots(t, env.gopts)
|
newest, _ = testRunSnapshots(t, env.gopts)
|
||||||
rtest.Assert(t, newest != nil, "expected a new backup, got nil")
|
if newest == nil {
|
||||||
|
t.Fatal("expected a backup, got nil")
|
||||||
|
}
|
||||||
rtest.Assert(t, len(newest.Tags) == 0,
|
rtest.Assert(t, len(newest.Tags) == 0,
|
||||||
"expected no tags, got %v", newest.Tags)
|
"expected no tags, got %v", newest.Tags)
|
||||||
rtest.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
|
rtest.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
|
||||||
|
@ -885,7 +904,9 @@ func TestTag(t *testing.T) {
|
||||||
testRunTag(t, TagOptions{SetTags: restic.TagLists{[]string{""}}}, env.gopts)
|
testRunTag(t, TagOptions{SetTags: restic.TagLists{[]string{""}}}, env.gopts)
|
||||||
testRunCheck(t, env.gopts)
|
testRunCheck(t, env.gopts)
|
||||||
newest, _ = testRunSnapshots(t, env.gopts)
|
newest, _ = testRunSnapshots(t, env.gopts)
|
||||||
rtest.Assert(t, newest != nil, "expected a new backup, got nil")
|
if newest == nil {
|
||||||
|
t.Fatal("expected a backup, got nil")
|
||||||
|
}
|
||||||
rtest.Assert(t, len(newest.Tags) == 0,
|
rtest.Assert(t, len(newest.Tags) == 0,
|
||||||
"expected no tags, got %v", newest.Tags)
|
"expected no tags, got %v", newest.Tags)
|
||||||
rtest.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
|
rtest.Assert(t, newest.Original != nil, "expected original snapshot id, got nil")
|
||||||
|
|
|
@ -228,12 +228,11 @@ func newBackend(cfg Config, lim limiter.Limiter) (*Backend, error) {
|
||||||
// rclone is able to accept HTTP requests.
|
// rclone is able to accept HTTP requests.
|
||||||
url := fmt.Sprintf("http://localhost/file-%d", rand.Uint64())
|
url := fmt.Sprintf("http://localhost/file-%d", rand.Uint64())
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req.Header.Set("Accept", rest.ContentTypeV2)
|
req.Header.Set("Accept", rest.ContentTypeV2)
|
||||||
req.Cancel = ctx.Done()
|
|
||||||
|
|
||||||
res, err := ctxhttp.Do(ctx, client, req)
|
res, err := ctxhttp.Do(ctx, client, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue