mirror of
https://github.com/kopia/kopia.git
synced 2026-05-18 11:44:36 -04:00
fix(general): enable wsl for all go files (#4524)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
@@ -119,7 +119,6 @@ linters:
|
||||
- perfsprint
|
||||
- revive
|
||||
- wrapcheck
|
||||
- wsl
|
||||
- text: "log is a global variable"
|
||||
linters:
|
||||
- gochecknoglobals
|
||||
|
||||
@@ -97,6 +97,7 @@ func TestNotificationProfile_WebHook(t *testing.T) {
|
||||
testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "notification", "profile", "show", "--profile-name=myotherwebhook", "--json", "--raw"), &opt)
|
||||
|
||||
var summ notifyprofile.Summary
|
||||
|
||||
testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "notification", "profile", "show", "--profile-name=myotherwebhook", "--json"), &summ)
|
||||
|
||||
require.Equal(t, []string{
|
||||
|
||||
@@ -97,6 +97,7 @@ func TestNotificationTemplates(t *testing.T) {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ func TestExportPolicy(t *testing.T) {
|
||||
|
||||
// check if we get the new policy
|
||||
var policies3 map[string]*policy.Policy
|
||||
|
||||
testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "policy", "export", id), &policies3)
|
||||
|
||||
assert.Len(t, policies3, 1, "unexpected number of policies")
|
||||
@@ -64,6 +65,7 @@ func TestExportPolicy(t *testing.T) {
|
||||
|
||||
// specifying a local id should return the same policy
|
||||
var policies4 map[string]*policy.Policy
|
||||
|
||||
testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "policy", "export", td), &policies4) // note: td, not id
|
||||
|
||||
assert.Len(t, policies4, 1, "unexpected number of policies")
|
||||
@@ -71,6 +73,7 @@ func TestExportPolicy(t *testing.T) {
|
||||
|
||||
// exporting without specifying a policy should return all policies
|
||||
var policies5 map[string]*policy.Policy
|
||||
|
||||
testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "policy", "export"), &policies5)
|
||||
|
||||
assert.Len(t, policies5, 2, "unexpected number of policies")
|
||||
@@ -80,12 +83,14 @@ func TestExportPolicy(t *testing.T) {
|
||||
exportPath := path.Join(td, "exported.json")
|
||||
|
||||
e.RunAndExpectSuccess(t, "policy", "export", "--to-file", exportPath)
|
||||
|
||||
exportedContent, err := os.ReadFile(exportPath)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to read exported file: %v", err)
|
||||
}
|
||||
|
||||
var policies6 map[string]*policy.Policy
|
||||
|
||||
testutil.MustParseJSONLines(t, []string{string(exportedContent)}, &policies6)
|
||||
|
||||
assert.Equal(t, expectedPolicies, policies6, "unexpected policy")
|
||||
@@ -102,6 +107,7 @@ func TestExportPolicy(t *testing.T) {
|
||||
}
|
||||
|
||||
var policies7 map[string]*policy.Policy
|
||||
|
||||
testutil.MustParseJSONLines(t, []string{string(exportedContent)}, &policies7)
|
||||
|
||||
// we specified id, so only that policy should be exported
|
||||
@@ -112,10 +118,13 @@ func TestExportPolicy(t *testing.T) {
|
||||
policies8prettyJSON := e.RunAndExpectSuccess(t, "policy", "export", "--json-indent")
|
||||
|
||||
var policies8pretty map[string]*policy.Policy
|
||||
|
||||
testutil.MustParseJSONLines(t, policies8prettyJSON, &policies8pretty)
|
||||
|
||||
policies8JSON := e.RunAndExpectSuccess(t, "policy", "export")
|
||||
|
||||
var policies8 map[string]*policy.Policy
|
||||
|
||||
testutil.MustParseJSONLines(t, policies8JSON, &policies8)
|
||||
|
||||
assert.Equal(t, policies8, policies8pretty, "pretty-printing should not change the content")
|
||||
|
||||
@@ -30,7 +30,9 @@ func TestImportPolicy(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("unable to marshal policy: %v", err)
|
||||
}
|
||||
|
||||
var defaultPolicy *policy.Policy
|
||||
|
||||
testutil.MustParseJSONLines(t, []string{string(defaultPolicyJSON)}, &defaultPolicy)
|
||||
|
||||
specifiedPolicies := map[string]*policy.Policy{
|
||||
@@ -53,6 +55,7 @@ func TestImportPolicy(t *testing.T) {
|
||||
|
||||
// change the global policy
|
||||
specifiedPolicies["(global)"].SplitterPolicy.Algorithm = "FIXED-4M"
|
||||
|
||||
makePolicyFile()
|
||||
e.RunAndExpectSuccess(t, "policy", "import", "--from-file", policyFilePath)
|
||||
assertPoliciesEqual(t, e, specifiedPolicies)
|
||||
@@ -69,6 +72,7 @@ func TestImportPolicy(t *testing.T) {
|
||||
Algorithm: "FIXED-8M",
|
||||
},
|
||||
}
|
||||
|
||||
makePolicyFile()
|
||||
e.RunAndExpectSuccess(t, "policy", "import", "--from-file", policyFilePath)
|
||||
assertPoliciesEqual(t, e, specifiedPolicies)
|
||||
@@ -76,6 +80,7 @@ func TestImportPolicy(t *testing.T) {
|
||||
// import from a file specifying changes in both policies but limiting import to only one
|
||||
specifiedPolicies["(global)"].CompressionPolicy.CompressorName = "zstd"
|
||||
specifiedPolicies[id].CompressionPolicy.CompressorName = "gzip"
|
||||
|
||||
makePolicyFile()
|
||||
e.RunAndExpectSuccess(t, "policy", "import", "--from-file", policyFilePath, "(global)")
|
||||
|
||||
@@ -84,11 +89,13 @@ func TestImportPolicy(t *testing.T) {
|
||||
assertPoliciesEqual(t, e, specifiedPolicies)
|
||||
|
||||
specifiedPolicies[id].CompressionPolicy.CompressorName = "gzip"
|
||||
|
||||
e.RunAndExpectSuccess(t, "policy", "import", "--from-file", policyFilePath, id)
|
||||
assertPoliciesEqual(t, e, specifiedPolicies)
|
||||
|
||||
// deleting values should work
|
||||
specifiedPolicies[id].CompressionPolicy.CompressorName = ""
|
||||
|
||||
makePolicyFile()
|
||||
e.RunAndExpectSuccess(t, "policy", "import", "--from-file", policyFilePath, id)
|
||||
assertPoliciesEqual(t, e, specifiedPolicies)
|
||||
@@ -106,6 +113,7 @@ func TestImportPolicy(t *testing.T) {
|
||||
},
|
||||
}
|
||||
specifiedPolicies[id2] = policy2
|
||||
|
||||
makePolicyFile()
|
||||
e.RunAndExpectSuccess(t, "policy", "import", "--from-file", policyFilePath, id2)
|
||||
assertPoliciesEqual(t, e, specifiedPolicies)
|
||||
@@ -130,6 +138,7 @@ func TestImportPolicy(t *testing.T) {
|
||||
|
||||
// add it back in
|
||||
specifiedPolicies[id2] = policy2
|
||||
|
||||
makePolicyFile()
|
||||
e.RunAndExpectSuccess(t, "policy", "import", "--from-file", policyFilePath)
|
||||
assertPoliciesEqual(t, e, specifiedPolicies)
|
||||
@@ -142,6 +151,7 @@ func TestImportPolicy(t *testing.T) {
|
||||
|
||||
// --global should be equivalent to (global)
|
||||
specifiedPolicies[id2] = policy2
|
||||
|
||||
makePolicyFile()
|
||||
e.RunAndExpectSuccess(t, "policy", "import", "--from-file", policyFilePath, "--global")
|
||||
delete(specifiedPolicies, id2) // should NOT have been imported
|
||||
@@ -153,6 +163,7 @@ func TestImportPolicy(t *testing.T) {
|
||||
|
||||
// another sanity check
|
||||
e.RunAndExpectSuccess(t, "policy", "import", "--from-file", policyFilePath)
|
||||
|
||||
specifiedPolicies[id2] = policy2
|
||||
assertPoliciesEqual(t, e, specifiedPolicies)
|
||||
|
||||
@@ -164,12 +175,15 @@ func TestImportPolicy(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("unable to write policy file: %v", err)
|
||||
}
|
||||
|
||||
e.RunAndExpectFailure(t, "policy", "import", "--from-file", policyFilePath)
|
||||
}
|
||||
|
||||
func assertPoliciesEqual(t *testing.T, e *testenv.CLITest, expected map[string]*policy.Policy) {
|
||||
t.Helper()
|
||||
|
||||
var policies map[string]*policy.Policy
|
||||
|
||||
testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "policy", "export"), &policies)
|
||||
|
||||
assert.Equal(t, expected, policies, "unexpected policies")
|
||||
|
||||
@@ -421,6 +421,7 @@ func TestRepositoryUpgrade_checkIndexInfo(t *testing.T) {
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
report := cli.CheckIndexInfo(tc.indexInfo0, tc.indexInfo1)
|
||||
require.Len(t, tc.expectRegexs, len(report), "unexpected report length")
|
||||
|
||||
for i := range tc.expectRegexs {
|
||||
require.Regexp(t, tc.expectRegexs[i], report[i], "report does not match regular expression")
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ func TestServerControl(t *testing.T) {
|
||||
require.Eventually(t, func() bool {
|
||||
lines := env.RunAndExpectSuccess(t, "server", "status", "--address", sp.BaseURL, "--server-control-password", sp.ServerControlPassword)
|
||||
t.Logf("lines: %v", lines)
|
||||
|
||||
return hasLine(lines, "IDLE: test-user@test-host:"+dir1) && hasLine(lines, "IDLE: test-user@test-host:"+dir2)
|
||||
}, waitTimeout, pollFrequency)
|
||||
|
||||
@@ -75,6 +76,7 @@ func TestServerControl(t *testing.T) {
|
||||
require.Eventually(t, func() bool {
|
||||
lines := env.RunAndExpectSuccess(t, "server", "status", "--address", sp.BaseURL, "--server-control-password", sp.ServerControlPassword, "--remote")
|
||||
t.Logf("lines: %v", lines)
|
||||
|
||||
return hasLine(lines, "IDLE: test-user@test-host:"+dir3)
|
||||
}, waitTimeout, pollFrequency)
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ func TestServerNotifications(t *testing.T) {
|
||||
|
||||
mux.HandleFunc("/notification-webhook", func(w http.ResponseWriter, r *http.Request) {
|
||||
var b bytes.Buffer
|
||||
|
||||
io.Copy(&b, r.Body)
|
||||
|
||||
notificationsReceived <- b.String()
|
||||
|
||||
@@ -311,6 +311,7 @@ func TestSnapshotFix(t *testing.T) {
|
||||
env.RunAndExpectFailure(t, append([]string{"snapshot", "fix"}, tc.flags...)...)
|
||||
env.RunAndExpectFailure(t, append(append([]string{"snapshot", "fix"}, tc.flags...), "--commit")...)
|
||||
env.RunAndExpectFailure(t, "snapshot", "verify")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -566,6 +566,7 @@ func TestIgnoreFS(t *testing.T) {
|
||||
if tc.setup != nil {
|
||||
tc.setup(root)
|
||||
}
|
||||
|
||||
ifs := ignorefs.New(root, tc.policyTree)
|
||||
|
||||
expectedFiles := addAndSubtractFiles(originalFiles, tc.addedFiles, tc.ignoredFiles)
|
||||
|
||||
@@ -32,6 +32,7 @@ func CleanupOldData(ctx context.Context, tb testing.TB, st blob.Storage, cleanup
|
||||
return st.DeleteBlob(ctx, it.BlobID)
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ func VerifyConcurrentAccess(t *testing.T, st blob.Storage, options ConcurrentAcc
|
||||
}
|
||||
|
||||
err := st.GetBlob(ctx, blobID, offset, length, &data)
|
||||
|
||||
switch {
|
||||
case err == nil:
|
||||
if got, want := string(data.ToByteSlice()), string(blobID); !strings.HasPrefix(got, want) {
|
||||
@@ -93,6 +94,7 @@ func VerifyConcurrentAccess(t *testing.T, st blob.Storage, options ConcurrentAcc
|
||||
for range options.Iterations {
|
||||
blobID := randomBlobID()
|
||||
data := fmt.Sprintf("%v-%v", blobID, rand.Int63())
|
||||
|
||||
err := st.PutBlob(ctx, blobID, gather.FromSlice([]byte(data)), blob.PutOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "PutBlob %v returned unexpected error", blobID)
|
||||
@@ -109,6 +111,7 @@ func VerifyConcurrentAccess(t *testing.T, st blob.Storage, options ConcurrentAcc
|
||||
for range options.Iterations {
|
||||
blobID := randomBlobID()
|
||||
err := st.DeleteBlob(ctx, blobID)
|
||||
|
||||
switch {
|
||||
case err == nil:
|
||||
// clean success
|
||||
@@ -130,6 +133,7 @@ func VerifyConcurrentAccess(t *testing.T, st blob.Storage, options ConcurrentAcc
|
||||
eg.Go(func() error {
|
||||
for range options.Iterations {
|
||||
blobID := randomBlobID()
|
||||
|
||||
prefix := blobID[0:rand.Intn(len(blobID))]
|
||||
if rand.Intn(100) < options.NonExistentListPrefixPercentage {
|
||||
prefix = "zzz"
|
||||
|
||||
@@ -95,6 +95,7 @@ func (s *FaultyStorage) ListBlobs(ctx context.Context, prefix blob.ID, callback
|
||||
if ok, err := s.GetNextFault(ctx, MethodListBlobsItem, prefix); ok {
|
||||
return err
|
||||
}
|
||||
|
||||
return callback(bm)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -106,6 +106,7 @@ func VerifyStorage(ctx context.Context, t *testing.T, r blob.Storage, opts blob.
|
||||
for _, b := range blocks {
|
||||
t.Run(string(b.blk), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
err := r.PutBlob(ctx, b.blk, gather.FromSlice(newContents), opts)
|
||||
if opts.DoNotRecreate {
|
||||
require.ErrorIsf(t, err, blob.ErrBlobAlreadyExists, "overwrote blob: %v", b)
|
||||
|
||||
1
internal/cache/content_cache_test.go
vendored
1
internal/cache/content_cache_test.go
vendored
@@ -209,6 +209,7 @@ func verifyContentCache(t *testing.T, cc cache.ContentCache, cacheStorage blob.S
|
||||
} else {
|
||||
require.ErrorContainsf(t, err, tc.err.Error(), "tc.contentID: %v", tc.contentID)
|
||||
}
|
||||
|
||||
if got := v.ToByteSlice(); !bytes.Equal(got, tc.expected) {
|
||||
t.Errorf("unexpected data for %v: %x, wanted %x", tc.contentID, got, tc.expected)
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ func TestConnection(t *testing.T) {
|
||||
// still using connection # 1
|
||||
if cnt == 0 {
|
||||
cnt++
|
||||
|
||||
require.EqualValues(t, 1, cli.(*fakeConnection).id)
|
||||
|
||||
cli.(*fakeConnection).isClosed = true
|
||||
@@ -106,6 +107,7 @@ func TestConnection(t *testing.T) {
|
||||
r.UsingConnectionNoResult(ctx, "third", func(cli connection.Connection) error {
|
||||
t.Logf("third called with %v", cli.(*fakeConnection).id)
|
||||
require.EqualValues(t, 2, cli.(*fakeConnection).id)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -118,6 +120,7 @@ func TestConnection(t *testing.T) {
|
||||
r.UsingConnectionNoResult(ctx, "parallel-2", func(cli connection.Connection) error {
|
||||
t.Logf("parallel-2 called with %v", cli.(*fakeConnection).id)
|
||||
require.EqualValues(t, 2, cli.(*fakeConnection).id)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -129,6 +132,7 @@ func TestConnection(t *testing.T) {
|
||||
require.NoError(t, r.UsingConnectionNoResult(ctx, "fourth", func(cli connection.Connection) error {
|
||||
t.Logf("fourth called with %v", cli.(*fakeConnection).id)
|
||||
require.EqualValues(t, 3, cli.(*fakeConnection).id)
|
||||
|
||||
return nil
|
||||
}))
|
||||
|
||||
@@ -146,6 +150,7 @@ func TestConnection(t *testing.T) {
|
||||
require.NoError(t, r.UsingConnectionNoResult(ctx, "sixth", func(cli connection.Connection) error {
|
||||
t.Logf("sixth called with %v", cli.(*fakeConnection).id)
|
||||
require.EqualValues(t, 4, cli.(*fakeConnection).id)
|
||||
|
||||
return nil
|
||||
}))
|
||||
|
||||
@@ -155,6 +160,7 @@ func TestConnection(t *testing.T) {
|
||||
return r.UsingConnectionNoResult(ctx, "parallel-a", func(cli connection.Connection) error {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
t.Logf("parallel-a called with %v", cli.(*fakeConnection).id)
|
||||
|
||||
return nil
|
||||
})
|
||||
})
|
||||
@@ -162,6 +168,7 @@ func TestConnection(t *testing.T) {
|
||||
return r.UsingConnectionNoResult(ctx, "parallel-b", func(cli connection.Connection) error {
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
t.Logf("parallel-b called with %v", cli.(*fakeConnection).id)
|
||||
|
||||
return nil
|
||||
})
|
||||
})
|
||||
@@ -169,6 +176,7 @@ func TestConnection(t *testing.T) {
|
||||
return r.UsingConnectionNoResult(ctx, "parallel-c", func(cli connection.Connection) error {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
t.Logf("parallel-c called with %v", cli.(*fakeConnection).id)
|
||||
|
||||
return nil
|
||||
})
|
||||
})
|
||||
|
||||
@@ -968,6 +968,7 @@ func TestMaybeCompactSingleEpoch(t *testing.T) {
|
||||
}
|
||||
|
||||
te.mustWriteIndexFiles(ctx, t, newFakeIndexWithEntries(k))
|
||||
|
||||
k++
|
||||
}
|
||||
|
||||
@@ -1088,6 +1089,7 @@ func TestMaybeGenerateRangeCheckpoint_CompactionError(t *testing.T) {
|
||||
}
|
||||
|
||||
te.mustWriteIndexFiles(ctx, t, newFakeIndexWithEntries(k))
|
||||
|
||||
k++
|
||||
}
|
||||
|
||||
@@ -1346,6 +1348,7 @@ func TestCleanupMarkers_FailToReadState(t *testing.T) {
|
||||
te.ft.Advance(1 * time.Hour) // force state refresh in CleanupMarkers
|
||||
|
||||
cancel()
|
||||
|
||||
err := te.mgr.CleanupMarkers(ctx)
|
||||
|
||||
require.Error(t, err)
|
||||
@@ -1391,6 +1394,7 @@ func TestCleanupMarkers_CleanUpManyMarkers(t *testing.T) {
|
||||
const epochsToAdvance = 5
|
||||
|
||||
te.mustWriteIndexFiles(ctx, t, newFakeIndexWithEntries(0))
|
||||
|
||||
for i := range epochsToAdvance {
|
||||
te.ft.Advance(p.MinEpochDuration + 1*time.Hour)
|
||||
te.mgr.forceAdvanceEpoch(ctx)
|
||||
|
||||
@@ -134,6 +134,7 @@ func TestLogFileRotation(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Logf("%v %v", info.Name(), info.Size())
|
||||
|
||||
if info.Mode().IsRegular() && info.Name() != cachedir.CacheDirMarkerFile {
|
||||
gotEntryCount++
|
||||
}
|
||||
|
||||
@@ -111,6 +111,7 @@ func TestWaitForActiveWorkers(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
results <- 1
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -214,6 +215,7 @@ func TestOnNthCompletion(t *testing.T) {
|
||||
for range n + 1 {
|
||||
go func() {
|
||||
results <- onNthCompletion()
|
||||
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -165,9 +165,11 @@ func TestDebug_parseProfileConfigs(t *testing.T) {
|
||||
require.Len(t, pbs, tc.n)
|
||||
pb, ok := pbs[tc.key] // no negative testing for missing keys (see newProfileConfigs)
|
||||
require.Equalf(t, !tc.expectMissing, ok, "key %q for set %q expect missing %t", tc.key, mapKeys(pbs), tc.expectMissing)
|
||||
|
||||
if tc.expectMissing {
|
||||
return
|
||||
}
|
||||
|
||||
require.Equal(t, 1<<10, pb.buf.Cap()) // bufsize is always 1024
|
||||
require.Equal(t, 0, pb.buf.Len())
|
||||
require.Equal(t, tc.expect, pb.flags)
|
||||
@@ -284,19 +286,25 @@ func TestDebug_LoadProfileConfigs(t *testing.T) {
|
||||
t.Run(fmt.Sprintf("%d: %q", i, tc.inArgs), func(t *testing.T) {
|
||||
pmp, err := LoadProfileConfig(ctx, tc.inArgs)
|
||||
require.ErrorIs(t, tc.expectError, err)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
val, ok := pmp[tc.profileKey]
|
||||
require.Equalf(t, tc.expectProfileConfigNotExists, !ok, "expecting key %q to %t exist", tc.profileKey, !tc.expectProfileConfigNotExists)
|
||||
|
||||
if tc.expectProfileConfigNotExists {
|
||||
return
|
||||
}
|
||||
|
||||
flagValue, ok := val.GetValue(tc.profileFlagKey)
|
||||
require.Equal(t, tc.expectProfileFlagExists, ok, "expecting key %q to %t exist", tc.profileKey, tc.expectProfileFlagExists)
|
||||
|
||||
if tc.expectProfileFlagExists {
|
||||
return
|
||||
}
|
||||
|
||||
require.Equal(t, tc.expectProfileFlagValue, flagValue)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -125,6 +125,7 @@ func TestSchedulerRefresh(t *testing.T) {
|
||||
|
||||
s := scheduler.Start(ctx, func(ctx context.Context, now time.Time) []scheduler.Item {
|
||||
t.Logf("now=%v", now)
|
||||
|
||||
switch cnt.Add(1) {
|
||||
case 1:
|
||||
return []scheduler.Item{{
|
||||
|
||||
@@ -172,6 +172,7 @@ func TestPolicies(t *testing.T) {
|
||||
|
||||
for j, ust := range res.UpcomingSnapshotTimes {
|
||||
require.Equal(t, ust.Truncate(60*time.Second), ust)
|
||||
|
||||
if j > 0 {
|
||||
require.Equal(t, 60*time.Second, ust.Sub(res.UpcomingSnapshotTimes[j-1]))
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ func VerifyTempfile(t *testing.T, create func() (*os.File, error)) {
|
||||
|
||||
require.Error(t, err)
|
||||
require.ErrorAs(t, err, &perr)
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
require.ErrorContains(t, err, "The system cannot find the file specified")
|
||||
} else {
|
||||
|
||||
@@ -103,6 +103,7 @@ func testUITaskInternal(t *testing.T, ctx context.Context, m *uitask.Manager) {
|
||||
"foo-notice": uitask.NoticeCounter(7),
|
||||
"bar-notice": uitask.NoticeBytesCounter(8),
|
||||
})
|
||||
|
||||
tsk, _ = m.GetTask(tid1a)
|
||||
if diff := cmp.Diff(tsk.Counters, map[string]uitask.CounterValue{
|
||||
"foo": {1, "", ""},
|
||||
@@ -273,6 +274,7 @@ func TestUITaskCancel_AfterOnCancel(t *testing.T) {
|
||||
|
||||
// send my task ID to the goroutine which will cancel our task
|
||||
ch <- tid
|
||||
|
||||
canceled := make(chan struct{})
|
||||
|
||||
ctrl.OnCancel(func() {
|
||||
@@ -312,8 +314,11 @@ func TestUITaskCancel_BeforeOnCancel(t *testing.T) {
|
||||
// send my task ID to the goroutine which will cancel our task
|
||||
tid = ctrl.CurrentTaskID()
|
||||
ch <- tid
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
canceled := make(chan struct{})
|
||||
|
||||
ctrl.OnCancel(func() {
|
||||
verifyTaskList(t, m, map[string]uitask.Status{
|
||||
tid: uitask.StatusCanceling,
|
||||
|
||||
@@ -31,6 +31,7 @@ func TestNonZeroDummyHash(t *testing.T) {
|
||||
// password hashers (PB key derivers in the crypto package).
|
||||
func TestSaltLengthIsSupported(t *testing.T) {
|
||||
const badPwd = "password"
|
||||
|
||||
var salt [passwordHashSaltLength]byte
|
||||
|
||||
for _, v := range []int{ScryptHashVersion, Pbkdf2HashVersion} {
|
||||
|
||||
@@ -35,6 +35,7 @@ func TestJSONSender(t *testing.T) {
|
||||
Body: "test body 3",
|
||||
Severity: notification.SeverityError,
|
||||
}
|
||||
|
||||
require.NoError(t, p.Send(ctx, m1)) // will be ignored
|
||||
require.NoError(t, p.Send(ctx, m2))
|
||||
require.NoError(t, p.Send(ctx, m3))
|
||||
|
||||
@@ -22,10 +22,12 @@ func TestPushover(t *testing.T) {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
var requests []*http.Request
|
||||
|
||||
var requestBodies []bytes.Buffer
|
||||
|
||||
mux.HandleFunc("/some-path", func(w http.ResponseWriter, r *http.Request) {
|
||||
var b bytes.Buffer
|
||||
|
||||
io.Copy(&b, r.Body)
|
||||
|
||||
requestBodies = append(requestBodies, b)
|
||||
|
||||
@@ -21,6 +21,7 @@ func TestProvider(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, "Test sender", p.Summary())
|
||||
|
||||
m1 := &sender.Message{
|
||||
Subject: "test subject 1",
|
||||
}
|
||||
@@ -30,6 +31,7 @@ func TestProvider(t *testing.T) {
|
||||
m3 := &sender.Message{
|
||||
Subject: "test subject 3",
|
||||
}
|
||||
|
||||
p.Send(ctx, m1)
|
||||
p.Send(ctx, m2)
|
||||
p.Send(ctx, m3)
|
||||
@@ -47,6 +49,7 @@ func TestProvider_NotConfigured(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, "Test sender", p.Summary())
|
||||
|
||||
m1 := &sender.Message{
|
||||
Subject: "test subject 1",
|
||||
}
|
||||
|
||||
@@ -21,10 +21,12 @@ func TestWebhook(t *testing.T) {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
var requests []*http.Request
|
||||
|
||||
var requestBodies []bytes.Buffer
|
||||
|
||||
mux.HandleFunc("/some-path", func(w http.ResponseWriter, r *http.Request) {
|
||||
var b bytes.Buffer
|
||||
|
||||
io.Copy(&b, r.Body)
|
||||
|
||||
requestBodies = append(requestBodies, b)
|
||||
|
||||
@@ -268,6 +268,7 @@ func putBlobs(ctx context.Context, cli blob.Storage, blobID blob.ID, blobs []str
|
||||
|
||||
func createBucket(t *testing.T, opts bucketOpts) {
|
||||
t.Helper()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
cli, err := gcsclient.NewClient(ctx, option.WithCredentialsJSON(opts.credentialsJSON))
|
||||
@@ -276,6 +277,7 @@ func createBucket(t *testing.T, opts bucketOpts) {
|
||||
attrs := &gcsclient.BucketAttrs{}
|
||||
|
||||
bucketHandle := cli.Bucket(opts.bucket)
|
||||
|
||||
if opts.isLockedBucket {
|
||||
attrs.VersioningEnabled = true
|
||||
bucketHandle = bucketHandle.SetObjectRetention(true)
|
||||
@@ -299,6 +301,7 @@ func createBucket(t *testing.T, opts bucketOpts) {
|
||||
|
||||
func validateBucket(t *testing.T, opts bucketOpts) {
|
||||
t.Helper()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
cli, err := gcsclient.NewClient(ctx, option.WithCredentialsJSON(opts.credentialsJSON))
|
||||
|
||||
@@ -59,6 +59,7 @@ func TestGetBlobVersions(t *testing.T) {
|
||||
dm, err := deleteBlob(ctx, s, blobName)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
bm = append(bm, dm)
|
||||
|
||||
var b gather.WriteBuffer
|
||||
@@ -250,6 +251,7 @@ func TestGetBlobWithVersion(t *testing.T) {
|
||||
}
|
||||
|
||||
var i int
|
||||
|
||||
for _, b := range blobs {
|
||||
for _, bv := range b {
|
||||
m := metas[i]
|
||||
@@ -265,6 +267,7 @@ func TestGetBlobWithVersion(t *testing.T) {
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, c, b.ToByteSlice())
|
||||
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,6 +178,7 @@ func TestSFTPStorageValid(t *testing.T) {
|
||||
|
||||
// use context that gets canceled after opening storage to ensure it's not used beyond New().
|
||||
newctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
st, err := createSFTPStorage(newctx, t, sftp.Options{
|
||||
Path: "/upload",
|
||||
Host: host,
|
||||
|
||||
@@ -54,6 +54,7 @@ func TestIterateAllPrefixesInParallel(t *testing.T) {
|
||||
}, func(m blob.Metadata) error {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
got = append(got, m.BlobID)
|
||||
|
||||
return nil
|
||||
@@ -68,6 +69,7 @@ func TestIterateAllPrefixesInParallel(t *testing.T) {
|
||||
}, func(m blob.Metadata) error {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
got = append(got, m.BlobID)
|
||||
|
||||
return nil
|
||||
@@ -83,6 +85,7 @@ func TestIterateAllPrefixesInParallel(t *testing.T) {
|
||||
}, func(m blob.Metadata) error {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
got = append(got, m.BlobID)
|
||||
|
||||
return nil
|
||||
|
||||
@@ -88,6 +88,7 @@ func TestWebDAVStorageBuiltInServer(t *testing.T) {
|
||||
if err := os.RemoveAll(tmpDir); err != nil {
|
||||
t.Errorf("can't remove all: %q", tmpDir)
|
||||
}
|
||||
|
||||
os.MkdirAll(tmpDir, 0o700)
|
||||
|
||||
verifyWebDAVStorage(t, server.URL, "user", "password", shardSpec)
|
||||
@@ -138,6 +139,7 @@ func transformMissingPUTs(next http.Handler) http.HandlerFunc {
|
||||
for header, values := range rec.Header() {
|
||||
w.Header()[header] = values
|
||||
}
|
||||
|
||||
w.WriteHeader(result.StatusCode)
|
||||
io.Copy(w, result.Body)
|
||||
}
|
||||
|
||||
@@ -58,8 +58,10 @@ func (s *contentManagerSuite) TestContentIndexRecovery(t *testing.T) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
totalRecovered += len(infos)
|
||||
t.Logf("recovered %v contents", len(infos))
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -85,8 +87,10 @@ func (s *contentManagerSuite) TestContentIndexRecovery(t *testing.T) {
|
||||
if rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
|
||||
totalRecovered += len(infos)
|
||||
t.Logf("recovered %v contents", len(infos))
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -1297,16 +1297,20 @@ func (s *contentManagerSuite) TestHandleWriteErrors(t *testing.T) {
|
||||
defer bm.CloseShared(ctx)
|
||||
|
||||
var writeRetries []int
|
||||
|
||||
var cids []ID
|
||||
|
||||
for i, size := range tc.contentSizes {
|
||||
t.Logf(">>>> writing %v", i)
|
||||
cid, retries := writeContentWithRetriesAndVerify(ctx, t, bm, seededRandomData(i, size))
|
||||
writeRetries = append(writeRetries, retries)
|
||||
cids = append(cids, cid)
|
||||
}
|
||||
|
||||
if got, want := flushWithRetries(ctx, t, bm), tc.expectedFlushRetries; got != want {
|
||||
t.Fatalf("invalid # of flush retries %v, wanted %v", got, want)
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(writeRetries, tc.expectedWriteRetries); diff != "" {
|
||||
t.Fatalf("invalid # of write retries (-got,+want): %v", diff)
|
||||
}
|
||||
@@ -1345,6 +1349,7 @@ func (s *contentManagerSuite) TestRewriteNonDeleted(t *testing.T) {
|
||||
case 0:
|
||||
t.Logf("flushing and reopening")
|
||||
bm.Flush(ctx)
|
||||
|
||||
bm = s.newTestContentManagerWithCustomTime(t, st, fakeNow)
|
||||
defer bm.CloseShared(ctx)
|
||||
case 1:
|
||||
@@ -1356,6 +1361,7 @@ func (s *contentManagerSuite) TestRewriteNonDeleted(t *testing.T) {
|
||||
}
|
||||
|
||||
content1 := writeContentAndVerify(ctx, t, bm, seededRandomData(10, 100))
|
||||
|
||||
applyStep(action1)
|
||||
require.NoError(t, bm.RewriteContent(ctx, content1))
|
||||
applyStep(action2)
|
||||
@@ -1378,6 +1384,7 @@ func (s *contentManagerSuite) TestDisableFlush(t *testing.T) {
|
||||
for i := range 500 {
|
||||
writeContentAndVerify(ctx, t, bm, seededRandomData(i, 100))
|
||||
}
|
||||
|
||||
bm.Flush(ctx) // flush will not have effect
|
||||
bm.EnableIndexFlush(ctx)
|
||||
bm.Flush(ctx) // flush will not have effect
|
||||
@@ -1404,6 +1411,7 @@ func (s *contentManagerSuite) TestRewriteDeleted(t *testing.T) {
|
||||
keyTime := map[blob.ID]time.Time{}
|
||||
fakeNow := faketime.AutoAdvance(fakeTime, 1*time.Second)
|
||||
st := blobtesting.NewMapStorage(data, keyTime, fakeNow)
|
||||
|
||||
bm := s.newTestContentManagerWithCustomTime(t, st, fakeNow)
|
||||
defer bm.CloseShared(ctx)
|
||||
|
||||
@@ -1412,6 +1420,7 @@ func (s *contentManagerSuite) TestRewriteDeleted(t *testing.T) {
|
||||
case 0:
|
||||
t.Logf("flushing and reopening")
|
||||
bm.Flush(ctx)
|
||||
|
||||
bm = s.newTestContentManagerWithCustomTime(t, st, fakeNow)
|
||||
defer bm.CloseShared(ctx)
|
||||
case 1:
|
||||
@@ -1424,6 +1433,7 @@ func (s *contentManagerSuite) TestRewriteDeleted(t *testing.T) {
|
||||
|
||||
c1Bytes := seededRandomData(10, 100)
|
||||
content1 := writeContentAndVerify(ctx, t, bm, c1Bytes)
|
||||
|
||||
applyStep(action1)
|
||||
require.NoError(t, bm.DeleteContent(ctx, content1))
|
||||
applyStep(action2)
|
||||
@@ -1431,12 +1441,15 @@ func (s *contentManagerSuite) TestRewriteDeleted(t *testing.T) {
|
||||
if got, want := bm.RewriteContent(ctx, content1), ErrContentNotFound; !errors.Is(got, want) && got != nil {
|
||||
t.Errorf("unexpected error %v, wanted %v", got, want)
|
||||
}
|
||||
|
||||
applyStep(action3)
|
||||
|
||||
if action1 == 2 { // no flush
|
||||
verifyContentNotFound(ctx, t, bm, content1)
|
||||
} else {
|
||||
verifyDeletedContentRead(ctx, t, bm, content1, c1Bytes)
|
||||
}
|
||||
|
||||
dumpContentManagerData(t, data)
|
||||
})
|
||||
}
|
||||
@@ -1503,6 +1516,7 @@ func (s *contentManagerSuite) TestDeleteAndRecreate(t *testing.T) {
|
||||
defer bm3.CloseShared(ctx)
|
||||
|
||||
dumpContentManagerData(t, data)
|
||||
|
||||
if tc.isVisible {
|
||||
verifyContent(ctx, t, bm3, content1, seededRandomData(10, 100))
|
||||
} else {
|
||||
@@ -1624,6 +1638,7 @@ func (s *contentManagerSuite) TestIterateContents(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
var mu sync.Mutex
|
||||
|
||||
got := map[ID]bool{}
|
||||
|
||||
err := bm.IterateContents(ctx, tc.options, func(ci Info) error {
|
||||
@@ -1638,6 +1653,7 @@ func (s *contentManagerSuite) TestIterateContents(t *testing.T) {
|
||||
mu.Lock()
|
||||
got[ci.ContentID] = true
|
||||
mu.Unlock()
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -1929,6 +1945,7 @@ func (s *contentManagerSuite) verifyVersionCompat(t *testing.T, writeVersion for
|
||||
|
||||
dataSet[cid] = data
|
||||
}
|
||||
|
||||
verifyContentManagerDataSet(ctx, t, mgr, dataSet)
|
||||
|
||||
// delete random 3 items (map iteration order is random)
|
||||
@@ -1938,6 +1955,7 @@ func (s *contentManagerSuite) verifyVersionCompat(t *testing.T, writeVersion for
|
||||
t.Logf("deleting %v", blobID)
|
||||
require.NoError(t, mgr.DeleteContent(ctx, blobID))
|
||||
delete(dataSet, blobID)
|
||||
|
||||
cnt++
|
||||
|
||||
if cnt >= 3 {
|
||||
|
||||
@@ -54,6 +54,7 @@ func TestMerged(t *testing.T) {
|
||||
t.Errorf("iteration preferred deleted content over non-deleted")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}))
|
||||
|
||||
|
||||
@@ -226,7 +226,9 @@ func verifyPackedIndexes(t *testing.T, infos []Info, infoMap map[ID]Info, versio
|
||||
}
|
||||
|
||||
require.Equal(t, want, info2)
|
||||
|
||||
cnt++
|
||||
|
||||
return nil
|
||||
}))
|
||||
|
||||
@@ -253,11 +255,14 @@ func verifyPackedIndexes(t *testing.T, infos []Info, infoMap map[ID]Info, versio
|
||||
|
||||
for _, prefix := range prefixes {
|
||||
cnt2 := 0
|
||||
|
||||
require.NoError(t, ndx.Iterate(PrefixRange(prefix), func(info2 Info) error {
|
||||
cnt2++
|
||||
|
||||
if !strings.HasPrefix(info2.ContentID.String(), string(prefix)) {
|
||||
t.Errorf("unexpected item %v when iterating prefix %v", info2.ContentID, prefix)
|
||||
}
|
||||
|
||||
return nil
|
||||
}))
|
||||
t.Logf("found %v elements with prefix %q", cnt2, prefix)
|
||||
@@ -419,6 +424,7 @@ func fuzzTestIndexOpen(originalData []byte) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
cnt := 0
|
||||
_ = ndx.Iterate(AllIDs, func(cb Info) error {
|
||||
if cnt < 10 {
|
||||
@@ -426,7 +432,9 @@ func fuzzTestIndexOpen(originalData []byte) {
|
||||
|
||||
_, _ = ndx.GetInfo(cb.ContentID, &tmp)
|
||||
}
|
||||
|
||||
cnt++
|
||||
|
||||
return nil
|
||||
})
|
||||
})
|
||||
|
||||
@@ -569,6 +569,7 @@ func undeleteFakeContents(ctx context.Context, t *testing.T, m *ManagerV0, delet
|
||||
}
|
||||
|
||||
delete(deleted, n)
|
||||
|
||||
count--
|
||||
}
|
||||
|
||||
|
||||
@@ -178,6 +178,7 @@ func TestFormatUpgradeMultipleLocksRollback(t *testing.T) {
|
||||
// the first owner's lock
|
||||
{
|
||||
var backups []string
|
||||
|
||||
require.NoError(t, env.RootStorage().ListBlobs(ctx, format.BackupBlobIDPrefix, func(bm blob.Metadata) error {
|
||||
backups = append(backups, string(bm.BlobID))
|
||||
return nil
|
||||
@@ -242,6 +243,7 @@ func(ctx context.Context, id blob.ID) error {
|
||||
if !allowGets && id == format.BackupBlobID(allowedLock) {
|
||||
return errors.New("unexpected error on get")
|
||||
}
|
||||
|
||||
return nil
|
||||
}, nil,
|
||||
func(ctx context.Context) error {
|
||||
@@ -256,6 +258,7 @@ func(ctx context.Context, id blob.ID, _ *blob.PutOptions) error {
|
||||
if !allowPuts || (strings.HasPrefix(string(id), format.BackupBlobIDPrefix) && id != format.BackupBlobID(allowedLock)) {
|
||||
return errors.New("unexpected error")
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
))
|
||||
|
||||
@@ -82,6 +82,7 @@ func (s *formatSpecificTestSuite) TestContentRewrite(t *testing.T) {
|
||||
ow := w.NewObjectWriter(ctx, object.WriterOptions{MetadataCompressor: "zstd-fastest"})
|
||||
fmt.Fprintf(ow, "%v", uuid.NewString())
|
||||
_, err := ow.Result()
|
||||
|
||||
return err
|
||||
}))
|
||||
}
|
||||
@@ -91,6 +92,7 @@ func (s *formatSpecificTestSuite) TestContentRewrite(t *testing.T) {
|
||||
ow := w.NewObjectWriter(ctx, object.WriterOptions{Prefix: "k", MetadataCompressor: "zstd-fastest"})
|
||||
fmt.Fprintf(ow, "%v", uuid.NewString())
|
||||
_, err := ow.Result()
|
||||
|
||||
return err
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ func TestQuickMaintenanceAdvancesEpoch(t *testing.T) {
|
||||
|
||||
// advance time and write more index to force epoch advancement on maintenance
|
||||
ft.Advance(epochDuration + time.Second)
|
||||
|
||||
ow := env.RepositoryWriter.NewObjectWriter(ctx, object.WriterOptions{})
|
||||
require.NotNil(t, ow)
|
||||
|
||||
|
||||
@@ -36,8 +36,10 @@ func (s *formatSpecificTestSuite) TestMaintenanceSafety(t *testing.T) {
|
||||
require.NoError(t, repo.WriteSession(ctx, env.Repository, repo.WriteSessionOptions{}, func(ctx context.Context, w repo.RepositoryWriter) error {
|
||||
ow := w.NewObjectWriter(ctx, object.WriterOptions{Prefix: "y", MetadataCompressor: "zstd-fastest"})
|
||||
fmt.Fprintf(ow, "hello world")
|
||||
|
||||
var err error
|
||||
objectID, err = ow.Result()
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
@@ -46,6 +48,7 @@ func (s *formatSpecificTestSuite) TestMaintenanceSafety(t *testing.T) {
|
||||
ow := w.NewObjectWriter(ctx, object.WriterOptions{Prefix: "y", MetadataCompressor: "zstd-fastest"})
|
||||
fmt.Fprintf(ow, "hello universe")
|
||||
_, err := ow.Result()
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
@@ -115,6 +118,7 @@ func verifyObjectReadable(ctx context.Context, t *testing.T, rep repo.Repository
|
||||
r, err := w.OpenObject(ctx, objectID)
|
||||
require.NoError(t, err)
|
||||
r.Close()
|
||||
|
||||
return nil
|
||||
}))
|
||||
}
|
||||
@@ -125,6 +129,7 @@ func verifyObjectNotFound(ctx context.Context, t *testing.T, rep repo.Repository
|
||||
require.NoError(t, repo.WriteSession(ctx, rep, repo.WriteSessionOptions{}, func(ctx context.Context, w repo.RepositoryWriter) error {
|
||||
_, err := w.OpenObject(ctx, objectID)
|
||||
require.ErrorIs(t, err, object.ErrObjectNotFound)
|
||||
|
||||
return nil
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -444,10 +444,12 @@ func() {
|
||||
if !c.HasPrefix() {
|
||||
t.Errorf("expected base content ID to be prefixed, was %v", c)
|
||||
}
|
||||
|
||||
info, err := om.contentMgr.ContentInfo(ctx, c)
|
||||
if err != nil {
|
||||
t.Errorf("error getting content info for %v", err.Error())
|
||||
}
|
||||
|
||||
require.Equal(t, expectedComp, info.CompressionHeaderID)
|
||||
}
|
||||
|
||||
@@ -530,6 +532,7 @@ func TestIndirection(t *testing.T) {
|
||||
if len(c.metadataCompressor) > 0 && c.metadataCompressor != "none" {
|
||||
expectedCompressor = compression.ByName[c.metadataCompressor].HeaderID()
|
||||
}
|
||||
|
||||
verifyIndirectBlock(ctx, t, om, result, expectedCompressor)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,6 +452,7 @@ func(ctx context.Context, id blob.ID) error {
|
||||
if id == format.KopiaRepositoryBlobID {
|
||||
return blob.ErrBlobNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
}, nil, nil, nil,
|
||||
),
|
||||
@@ -473,9 +474,11 @@ func(ctx context.Context, id blob.ID) error {
|
||||
if id == format.KopiaBlobCfgBlobID {
|
||||
return nil
|
||||
}
|
||||
|
||||
if id == format.KopiaRepositoryBlobID {
|
||||
return blob.ErrBlobNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
}, nil, nil, nil,
|
||||
),
|
||||
@@ -496,6 +499,7 @@ func(ctx context.Context, id blob.ID) error {
|
||||
if id == format.KopiaBlobCfgBlobID || id == format.KopiaRepositoryBlobID {
|
||||
return blob.ErrBlobNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
nil, nil,
|
||||
@@ -504,6 +508,7 @@ func(ctx context.Context, id blob.ID, _ *blob.PutOptions) error {
|
||||
if id == format.KopiaBlobCfgBlobID {
|
||||
return errors.New("unexpected error")
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
),
|
||||
@@ -527,6 +532,7 @@ func(ctx context.Context, id blob.ID) error {
|
||||
if id == format.KopiaRepositoryBlobID {
|
||||
return errors.New("unexpected error")
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
nil, nil, nil,
|
||||
@@ -582,11 +588,14 @@ func TestObjectWritesWithRetention(t *testing.T) {
|
||||
if strings.HasPrefix(string(it.BlobID), prefix) {
|
||||
_, err = versionedMap.TouchBlob(ctx, it.BlobID, 0)
|
||||
require.Error(t, err, "expected error while touching blob %s", it.BlobID)
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
_, err = versionedMap.TouchBlob(ctx, it.BlobID, 0)
|
||||
require.NoError(t, err, "unexpected error while touching blob %s", it.BlobID)
|
||||
|
||||
return nil
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -136,6 +136,7 @@ func TestPolicyManagerInheritanceTest(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(pol, tc.wantEffective); diff != "" {
|
||||
t.Errorf("got: %v", pol)
|
||||
t.Errorf("want: %v", tc.wantEffective)
|
||||
|
||||
@@ -163,6 +163,7 @@ func TestRetentionPolicyTest(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(fmt.Sprintf("%v", tc), func(t *testing.T) {
|
||||
var manifests []*snapshot.Manifest
|
||||
|
||||
var manifests2 []*snapshot.Manifest
|
||||
|
||||
for ts, want := range tc.timeToExpectedTags {
|
||||
@@ -170,6 +171,7 @@ func TestRetentionPolicyTest(t *testing.T) {
|
||||
if strings.HasPrefix(ts, "incomplete-") {
|
||||
incompleteReason = "some-reason"
|
||||
}
|
||||
|
||||
startTime, err := time.Parse(time.RFC3339, strings.TrimPrefix(ts, "incomplete-"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -34,7 +34,9 @@ func TestSnapshotVerifier(t *testing.T) {
|
||||
require.NoError(t, repo.WriteSession(ctx, te.Repository, repo.WriteSessionOptions{}, func(ctx context.Context, w repo.RepositoryWriter) error {
|
||||
snap1, err := u.Upload(ctx, dir1, nil, si1)
|
||||
require.NoError(t, err)
|
||||
|
||||
obj1 = snap1.RootObjectID()
|
||||
|
||||
return nil
|
||||
}))
|
||||
|
||||
|
||||
@@ -278,6 +278,7 @@ func (s *formatSpecificTestSuite) TestMaintenanceAutoLiveness(t *testing.T) {
|
||||
|
||||
dp := maintenance.DefaultParams()
|
||||
dp.Owner = env.Repository.ClientOptions().UsernameAtHost()
|
||||
|
||||
return maintenance.SetParams(ctx, w, &dp)
|
||||
}))
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ func (w *mockLogger) Sync() error {
|
||||
|
||||
func getMockLogger() logging.Logger {
|
||||
ml := &mockLogger{}
|
||||
|
||||
return zap.New(
|
||||
zapcore.NewCore(
|
||||
zapcore.NewConsoleEncoder(zapcore.EncoderConfig{
|
||||
@@ -81,6 +82,7 @@ func expectSuccessfulEstimation(
|
||||
expectedDataSize int64,
|
||||
) {
|
||||
t.Helper()
|
||||
|
||||
var filesCount, totalFileSize int64
|
||||
|
||||
done := make(chan struct{})
|
||||
|
||||
@@ -239,10 +239,13 @@ type entry struct {
|
||||
// findAllEntries recursively iterates over all the dirs and returns list of file entries.
|
||||
func findAllEntries(t *testing.T, ctx context.Context, dir fs.Directory) []entry {
|
||||
t.Helper()
|
||||
|
||||
entries := []entry{}
|
||||
|
||||
fs.IterateEntries(ctx, dir, func(ctx context.Context, e fs.Entry) error {
|
||||
oid, err := object.ParseID(e.(object.HasObjectID).ObjectID().String())
|
||||
require.NoError(t, err)
|
||||
|
||||
entries = append(entries, entry{
|
||||
name: e.Name(),
|
||||
objectID: oid,
|
||||
@@ -250,6 +253,7 @@ func findAllEntries(t *testing.T, ctx context.Context, dir fs.Directory) []entry
|
||||
if e.IsDir() {
|
||||
entries = append(entries, findAllEntries(t, ctx, e.(fs.Directory))...)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -258,16 +262,20 @@ func findAllEntries(t *testing.T, ctx context.Context, dir fs.Directory) []entry
|
||||
|
||||
func verifyMetadataCompressor(t *testing.T, ctx context.Context, rep repo.Repository, entries []entry, comp compression.HeaderID) {
|
||||
t.Helper()
|
||||
|
||||
for _, e := range entries {
|
||||
cid, _, ok := e.objectID.ContentID()
|
||||
require.True(t, ok)
|
||||
|
||||
if !cid.HasPrefix() {
|
||||
continue
|
||||
}
|
||||
|
||||
info, err := rep.ContentInfo(ctx, cid)
|
||||
if err != nil {
|
||||
t.Errorf("failed to get content info: %v", err)
|
||||
}
|
||||
|
||||
require.Equal(t, comp, info.CompressionHeaderID)
|
||||
}
|
||||
}
|
||||
@@ -845,6 +853,7 @@ func TestParallelUploadUploadsBlobsInParallel(t *testing.T) {
|
||||
th.faulty.AddFault(blobtesting.MethodPutBlob).Repeat(10).Before(func() {
|
||||
v := currentParallelCalls.Add(1)
|
||||
maxParallelism := maxParallelCalls.Load()
|
||||
|
||||
if v > maxParallelism {
|
||||
maxParallelCalls.CompareAndSwap(maxParallelism, v)
|
||||
}
|
||||
@@ -1298,6 +1307,7 @@ func TestParallelUploadOfLargeFiles(t *testing.T) {
|
||||
// and were concatenated
|
||||
for offset := int64(0); offset < f.Size(); offset += chunkSize {
|
||||
verifyContainsOffset(t, entries, chunkSize)
|
||||
|
||||
successCount++
|
||||
}
|
||||
|
||||
@@ -1660,6 +1670,7 @@ func TestUploadLogging(t *testing.T) {
|
||||
|
||||
pol := *policy.DefaultPolicy
|
||||
pol.OSSnapshotPolicy.VolumeShadowCopy.Enable = policy.NewOSSnapshotMode(policy.OSSnapshotNever)
|
||||
|
||||
if p := tc.globalLoggingPolicy; p != nil {
|
||||
pol.LoggingPolicy = *p
|
||||
}
|
||||
|
||||
@@ -53,12 +53,14 @@ func TestAutoUpdateEnableTest(t *testing.T) {
|
||||
e.RunAndExpectSuccess(t, args...)
|
||||
|
||||
updateInfoFile := filepath.Join(e.ConfigDir, ".kopia.config.update-info.json")
|
||||
|
||||
_, err := os.Stat(updateInfoFile)
|
||||
if got, want := err == nil, tc.wantEnabled; got != want {
|
||||
t.Errorf("update check enabled: %v, wanted %v", got, want)
|
||||
}
|
||||
|
||||
e.RunAndExpectSuccess(t, "repo", "disconnect")
|
||||
|
||||
if _, err = os.Stat(updateInfoFile); !os.IsNotExist(err) {
|
||||
t.Errorf("update info file was not removed.")
|
||||
}
|
||||
@@ -73,6 +75,7 @@ func TestAutoUpdateEnableTest(t *testing.T) {
|
||||
if got, want := err == nil, tc.wantEnabled; got != want {
|
||||
t.Fatalf("update check enabled: %v, wanted %v", got, want)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
defer f.Close()
|
||||
|
||||
|
||||
@@ -74,7 +74,9 @@ func (s *formatSpecificTestSuite) TestCompression(t *testing.T) {
|
||||
for _, l := range lines {
|
||||
if strings.HasPrefix(l, entries[0].ObjectID) {
|
||||
require.Contains(t, l, "pgzip")
|
||||
|
||||
found = true
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,9 +100,11 @@ func (s *formatSpecificTestSuite) flipOneByteFromEachFile(e *testenv.CLITest) er
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if info.Name() == "kopia.repository.f" || info.Name() == ".shards" {
|
||||
return nil
|
||||
}
|
||||
@@ -135,9 +137,11 @@ func dirSize(path string) (int64, error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !info.IsDir() {
|
||||
size += info.Size()
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@ func TestReconnectUsingToken(t *testing.T) {
|
||||
|
||||
func TestRepoConnectKeyDerivationAlgorithm(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for _, algorithm := range format.SupportedFormatBlobKeyDerivationAlgorithms() {
|
||||
runner := testenv.NewInProcRunner(t)
|
||||
e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner)
|
||||
@@ -121,7 +122,9 @@ func TestRepoConnectKeyDerivationAlgorithm(t *testing.T) {
|
||||
kopiaRepoPath := filepath.Join(e.RepoDir, "kopia.repository.f")
|
||||
dat, err := os.ReadFile(kopiaRepoPath)
|
||||
require.NoError(t, err)
|
||||
|
||||
var repoJSON format.KopiaRepositoryJSON
|
||||
|
||||
json.Unmarshal(dat, &repoJSON)
|
||||
require.Equal(t, repoJSON.KeyDerivationAlgorithm, algorithm)
|
||||
}
|
||||
@@ -138,7 +141,9 @@ func TestRepoConnectBadKeyDerivationAlgorithm(t *testing.T) {
|
||||
kopiaRepoPath := filepath.Join(e.RepoDir, "kopia.repository.f")
|
||||
dat, err := os.ReadFile(kopiaRepoPath)
|
||||
require.NoError(t, err)
|
||||
|
||||
var repoJSON format.KopiaRepositoryJSON
|
||||
|
||||
json.Unmarshal(dat, &repoJSON)
|
||||
|
||||
repoJSON.KeyDerivationAlgorithm = "badalgorithm"
|
||||
|
||||
@@ -344,6 +344,7 @@ func TestSnapshotRestore(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.fname, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fname := filepath.Join(restoreArchiveDir, tc.fname)
|
||||
e.RunAndExpectSuccess(t, append([]string{"snapshot", "restore", snapID, fname}, tc.args...)...)
|
||||
tc.validator(t, fname)
|
||||
|
||||
@@ -627,6 +627,7 @@ func findRealFileDir(t *testing.T, original string) (dir, file string) {
|
||||
case file != "" && dir != "":
|
||||
return filepath.SkipDir
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -339,6 +339,7 @@ func TestSnapshotActionsEnable(t *testing.T) {
|
||||
e.RunAndExpectSuccess(t, append([]string{"snapshot", "create", sharedTestDataDir1}, tc.snapshotFlags...)...)
|
||||
|
||||
_, err := os.Stat(envFile)
|
||||
|
||||
didRun := err == nil
|
||||
if didRun != tc.wantRun {
|
||||
t.Errorf("unexpected behavior. did run: %v want run: %v", didRun, tc.wantRun)
|
||||
|
||||
@@ -530,6 +530,7 @@ func TestSnapshotCreateWithIgnore(t *testing.T) {
|
||||
var expected []string
|
||||
for _, ex := range tc.expected {
|
||||
expected = appendIfMissing(expected, ex)
|
||||
|
||||
if !strings.HasSuffix(ex, "/") {
|
||||
for d, _ := path.Split(ex); d != ""; d, _ = path.Split(d) {
|
||||
expected = appendIfMissing(expected, d)
|
||||
@@ -540,6 +541,7 @@ func TestSnapshotCreateWithIgnore(t *testing.T) {
|
||||
|
||||
sort.Strings(output)
|
||||
sort.Strings(expected)
|
||||
|
||||
if diff := pretty.Compare(output, expected); diff != "" {
|
||||
t.Errorf("unexpected directory tree, diff(-got,+want): %v\n", diff)
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ func TestEndurance(t *testing.T) {
|
||||
for i := range enduranceRunnerCount {
|
||||
t.Run(fmt.Sprintf("Runner-%v", i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
defer func() {
|
||||
if t.Failed() {
|
||||
failureCount.Add(1)
|
||||
|
||||
@@ -27,6 +27,7 @@ func (tc *TestContext) expectDialogText(txt string, respond bool) chromedp.Actio
|
||||
return chromedp.ActionFunc(func(c context.Context) error {
|
||||
tc.expectedDialogText = txt
|
||||
tc.dialogResponse = respond
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -335,6 +335,7 @@ func TestByteRepresentation(t *testing.T) {
|
||||
snap1Path := testutil.TempDirectory(t)
|
||||
|
||||
var base2 string
|
||||
|
||||
var base10 string
|
||||
|
||||
// create a test snaphot
|
||||
|
||||
@@ -422,6 +422,7 @@ func listAndReadAllContents(ctx context.Context, r repo.DirectRepositoryWriter,
|
||||
content.IterateOptions{},
|
||||
func(ci content.Info) error {
|
||||
cid := ci.ContentID
|
||||
|
||||
_, err := r.ContentReader().GetContent(ctx, cid)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error reading content %v", cid)
|
||||
|
||||
@@ -179,6 +179,7 @@ func (chk *Checker) VerifySnapshotMetadata(ctx context.Context) error {
|
||||
if chk.RecoveryMode {
|
||||
if liveSnapsDeleted >= chk.DeleteLimit {
|
||||
log.Printf("delete limit (%v) reached", chk.DeleteLimit)
|
||||
|
||||
errCount++
|
||||
}
|
||||
|
||||
@@ -188,6 +189,7 @@ func (chk *Checker) VerifySnapshotMetadata(ctx context.Context) error {
|
||||
err = chk.snapshotIssuer.DeleteSnapshot(ctx, liveSnapID, map[string]string{})
|
||||
if err != nil {
|
||||
log.Printf("error deleting snapshot: %s", err)
|
||||
|
||||
errCount++
|
||||
}
|
||||
|
||||
|
||||
@@ -160,6 +160,7 @@ func makeTempS3Bucket(t *testing.T) (bucketName string, cleanupCB func()) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ func (th *TestHarness) init(ctx context.Context) {
|
||||
log.Printf("Skipping robustness tests because repo-path-prefix is not set")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
dataRepoPath := path.Join(*RepoPathPrefix, dataSubPath)
|
||||
metaRepoPath := path.Join(*RepoPathPrefix, metadataSubPath)
|
||||
|
||||
@@ -314,6 +315,7 @@ func (th *TestHarness) GetDirsToLog(ctx context.Context) []string {
|
||||
if err == nil {
|
||||
dirList = append(dirList, cacheDir) // cache dir for repo under test
|
||||
}
|
||||
|
||||
allCacheDirs := getAllCacheDirs(cacheDir)
|
||||
dirList = append(dirList, allCacheDirs...)
|
||||
|
||||
@@ -324,6 +326,7 @@ func getAllCacheDirs(dir string) []string {
|
||||
if dir == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
var dirs []string
|
||||
// Collect all cache dirs
|
||||
// There are six types of caches, and corresponding dirs.
|
||||
|
||||
@@ -34,6 +34,7 @@ func TestMain(m *testing.M) {
|
||||
// Perform setup needed to get storage stats.
|
||||
dirs := th.GetDirsToLog(ctx)
|
||||
log.Printf("Logging storage stats for %v", dirs)
|
||||
|
||||
err := storagestats.LogStorageStats(ctx, dirs)
|
||||
if err != nil {
|
||||
log.Printf("Error collecting the logs: %s", err.Error())
|
||||
|
||||
@@ -243,6 +243,7 @@ func tryRandomAction(ctx context.Context, t *testing.T, opts engine.ActionOpts)
|
||||
// with options and masks no-op errors, and asserts when called for any other action.
|
||||
func tryDeleteAction(ctx context.Context, t *testing.T, action engine.ActionKey, actionOpts map[string]string) {
|
||||
t.Helper()
|
||||
|
||||
eligibleActionsList := []engine.ActionKey{
|
||||
engine.DeleteDirectoryContentsActionKey,
|
||||
engine.DeleteRandomSubdirectoryActionKey,
|
||||
|
||||
@@ -44,6 +44,7 @@ func LogStorageStats(ctx context.Context, dirs []string) error {
|
||||
|
||||
logFilePath = getLogFilePath()
|
||||
log.Printf("log file path %s", logFilePath)
|
||||
|
||||
err = os.WriteFile(logFilePath, jsonData, 0o644)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error writing log file: %w", err)
|
||||
@@ -65,8 +66,10 @@ func getSize(dirPath string) (int64, error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
size += info.Size()
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ func (kpl *KopiaPersisterLight) ConnectOrCreateRepo(repoPath string) error {
|
||||
// SetCacheLimits sets to an existing one if possible.
|
||||
func (kpl *KopiaPersisterLight) SetCacheLimits(repoPath string, cacheOpts *content.CachingOptions) error {
|
||||
bucketName := os.Getenv(S3BucketNameEnvKey)
|
||||
|
||||
err := kpl.kc.SetCacheLimits(context.Background(), repoPath, bucketName, cacheOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -140,6 +140,7 @@ func (fr *Runner) DeleteContentsAtDepth(relBasePath string, depth int, prob floa
|
||||
for _, entry := range dirEntries {
|
||||
if rand.Float32() < prob {
|
||||
path := filepath.Join(dirPath, entry.Name())
|
||||
|
||||
err = os.RemoveAll(path)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user