From 8a176255c0fbc810b3c5d07a115693d521558e35 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 26 Apr 2025 22:01:20 +0200 Subject: [PATCH] fix(general): enable wsl for all go files (#4524) Signed-off-by: Matthieu MOREL --- .golangci.yml | 1 - cli/command_notification_profile_test.go | 1 + cli/command_notification_template_test.go | 1 + cli/command_policy_export_test.go | 9 +++++++++ cli/command_policy_import_test.go | 14 ++++++++++++++ cli/command_repository_upgrade_test.go | 1 + cli/command_server_control_test.go | 2 ++ cli/command_server_notifications_test.go | 1 + cli/command_snapshot_fix_test.go | 1 + fs/ignorefs/ignorefs_test.go | 1 + internal/blobtesting/cleanup.go | 1 + internal/blobtesting/concurrent.go | 4 ++++ internal/blobtesting/faulty.go | 1 + internal/blobtesting/verify.go | 1 + internal/cache/content_cache_test.go | 1 + internal/connection/reconnector_test.go | 8 ++++++++ internal/epoch/epoch_manager_test.go | 4 ++++ internal/logfile/logfile_test.go | 1 + .../parallelwork/parallel_work_queue_test.go | 2 ++ internal/pproflogging/pproflogging_test.go | 8 ++++++++ internal/scheduler/scheduler_test.go | 1 + internal/server/api_policies_test.go | 1 + internal/tempfile/tempfile_verify_test.go | 1 + internal/uitask/uitask_test.go | 5 +++++ internal/user/password_hashings_test.go | 1 + .../sender/jsonsender/jsonsender_test.go | 1 + .../sender/pushover/pushover_sender_test.go | 2 ++ .../sender/testsender/test_sender_test.go | 3 +++ .../sender/webhook/webhook_sender_test.go | 2 ++ repo/blob/gcs/gcs_versioned_test.go | 3 +++ repo/blob/s3/s3_versioned_test.go | 3 +++ repo/blob/sftp/sftp_storage_test.go | 1 + repo/blob/storage_test.go | 3 +++ repo/blob/webdav/webdav_storage_test.go | 2 ++ repo/content/content_index_recovery_test.go | 4 ++++ repo/content/content_manager_test.go | 18 ++++++++++++++++++ repo/content/index/merged_test.go | 1 + repo/content/index/packindex_test.go | 8 ++++++++ .../indexblob/index_blob_manager_v0_test.go | 1 + repo/format/upgrade_lock_test.go | 3 +++ repo/maintenance/content_rewrite_test.go | 2 ++ repo/maintenance/maintenance_quick_test.go | 1 + repo/maintenance/maintenance_safety_test.go | 5 +++++ repo/object/object_manager_test.go | 3 +++ repo/repository_test.go | 9 +++++++++ snapshot/policy/policy_manager_test.go | 1 + snapshot/policy/retention_policy_test.go | 2 ++ snapshot/snapshotfs/snapshot_verifier_test.go | 2 ++ .../snapshotmaintenance_test.go | 1 + snapshot/upload/upload_estimator_test.go | 2 ++ snapshot/upload/upload_test.go | 11 +++++++++++ tests/end_to_end_test/auto_update_test.go | 3 +++ tests/end_to_end_test/compression_test.go | 2 ++ tests/end_to_end_test/ecc_test.go | 4 ++++ .../end_to_end_test/repository_connect_test.go | 5 +++++ tests/end_to_end_test/restore_test.go | 1 + tests/end_to_end_test/shallowrestore_test.go | 1 + tests/end_to_end_test/snapshot_actions_test.go | 1 + tests/end_to_end_test/snapshot_create_test.go | 2 ++ tests/endurance_test/endurance_test.go | 1 + tests/htmlui_e2e_test/context_test.go | 1 + tests/htmlui_e2e_test/htmlui_e2e_test.go | 1 + .../repository_stress_test.go | 1 + tests/robustness/checker/checker.go | 2 ++ tests/robustness/engine/engine_test.go | 1 + .../multiclient_test/framework/harness.go | 3 +++ tests/robustness/multiclient_test/main_test.go | 1 + .../multiclient_test/multiclient_test.go | 1 + .../storagestats/storage_stats.go | 3 +++ .../snapmeta/kopia_persister_light.go | 1 + tests/tools/fio/workload.go | 1 + 71 files changed, 201 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index ceca30b43..c0f32daca 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -119,7 +119,6 @@ linters: - perfsprint - revive - wrapcheck - - wsl - text: "log is a global variable" linters: - gochecknoglobals diff --git a/cli/command_notification_profile_test.go b/cli/command_notification_profile_test.go index 3114d6110..25dabd3b5 100644 --- a/cli/command_notification_profile_test.go +++ b/cli/command_notification_profile_test.go @@ -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{ diff --git a/cli/command_notification_template_test.go b/cli/command_notification_template_test.go index 19e387751..9e628455f 100644 --- a/cli/command_notification_template_test.go +++ b/cli/command_notification_template_test.go @@ -97,6 +97,7 @@ func TestNotificationTemplates(t *testing.T) { return nil } + return nil } diff --git a/cli/command_policy_export_test.go b/cli/command_policy_export_test.go index e119a66ab..4257d86db 100644 --- a/cli/command_policy_export_test.go +++ b/cli/command_policy_export_test.go @@ -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") diff --git a/cli/command_policy_import_test.go b/cli/command_policy_import_test.go index e1700065f..0589a31ce 100644 --- a/cli/command_policy_import_test.go +++ b/cli/command_policy_import_test.go @@ -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") diff --git a/cli/command_repository_upgrade_test.go b/cli/command_repository_upgrade_test.go index 51000996c..a9a995dd5 100644 --- a/cli/command_repository_upgrade_test.go +++ b/cli/command_repository_upgrade_test.go @@ -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") } diff --git a/cli/command_server_control_test.go b/cli/command_server_control_test.go index a9b1307fe..08927a74c 100644 --- a/cli/command_server_control_test.go +++ b/cli/command_server_control_test.go @@ -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) diff --git a/cli/command_server_notifications_test.go b/cli/command_server_notifications_test.go index c03775e22..59d0d7ad7 100644 --- a/cli/command_server_notifications_test.go +++ b/cli/command_server_notifications_test.go @@ -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() diff --git a/cli/command_snapshot_fix_test.go b/cli/command_snapshot_fix_test.go index f57d54e2a..c44100730 100644 --- a/cli/command_snapshot_fix_test.go +++ b/cli/command_snapshot_fix_test.go @@ -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 } diff --git a/fs/ignorefs/ignorefs_test.go b/fs/ignorefs/ignorefs_test.go index 4832f323e..7d1eef31e 100644 --- a/fs/ignorefs/ignorefs_test.go +++ b/fs/ignorefs/ignorefs_test.go @@ -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) diff --git a/internal/blobtesting/cleanup.go b/internal/blobtesting/cleanup.go index 1885b63ca..eef4a4244 100644 --- a/internal/blobtesting/cleanup.go +++ b/internal/blobtesting/cleanup.go @@ -32,6 +32,7 @@ func CleanupOldData(ctx context.Context, tb testing.TB, st blob.Storage, cleanup return st.DeleteBlob(ctx, it.BlobID) }) } + return nil }) diff --git a/internal/blobtesting/concurrent.go b/internal/blobtesting/concurrent.go index 482bfd46b..12d32e379 100644 --- a/internal/blobtesting/concurrent.go +++ b/internal/blobtesting/concurrent.go @@ -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" diff --git a/internal/blobtesting/faulty.go b/internal/blobtesting/faulty.go index f3c01df1b..f36e7360b 100644 --- a/internal/blobtesting/faulty.go +++ b/internal/blobtesting/faulty.go @@ -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) }) } diff --git a/internal/blobtesting/verify.go b/internal/blobtesting/verify.go index d81418b35..0a9d26f4d 100644 --- a/internal/blobtesting/verify.go +++ b/internal/blobtesting/verify.go @@ -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) diff --git a/internal/cache/content_cache_test.go b/internal/cache/content_cache_test.go index 4367849e5..c7b58a891 100644 --- a/internal/cache/content_cache_test.go +++ b/internal/cache/content_cache_test.go @@ -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) } diff --git a/internal/connection/reconnector_test.go b/internal/connection/reconnector_test.go index 563345ff8..0a0bd01de 100644 --- a/internal/connection/reconnector_test.go +++ b/internal/connection/reconnector_test.go @@ -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 }) }) diff --git a/internal/epoch/epoch_manager_test.go b/internal/epoch/epoch_manager_test.go index af2edf15b..4a3e8897f 100644 --- a/internal/epoch/epoch_manager_test.go +++ b/internal/epoch/epoch_manager_test.go @@ -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) diff --git a/internal/logfile/logfile_test.go b/internal/logfile/logfile_test.go index a2142da28..f4633dcc0 100644 --- a/internal/logfile/logfile_test.go +++ b/internal/logfile/logfile_test.go @@ -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++ } diff --git a/internal/parallelwork/parallel_work_queue_test.go b/internal/parallelwork/parallel_work_queue_test.go index b0359263d..7ef32f7cd 100644 --- a/internal/parallelwork/parallel_work_queue_test.go +++ b/internal/parallelwork/parallel_work_queue_test.go @@ -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() }() } diff --git a/internal/pproflogging/pproflogging_test.go b/internal/pproflogging/pproflogging_test.go index dc7e1cb79..44ab703c9 100644 --- a/internal/pproflogging/pproflogging_test.go +++ b/internal/pproflogging/pproflogging_test.go @@ -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) }) } diff --git a/internal/scheduler/scheduler_test.go b/internal/scheduler/scheduler_test.go index 8f2f4b7bb..3220cb8d5 100644 --- a/internal/scheduler/scheduler_test.go +++ b/internal/scheduler/scheduler_test.go @@ -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{{ diff --git a/internal/server/api_policies_test.go b/internal/server/api_policies_test.go index 13709d7eb..3f5fb0232 100644 --- a/internal/server/api_policies_test.go +++ b/internal/server/api_policies_test.go @@ -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])) } diff --git a/internal/tempfile/tempfile_verify_test.go b/internal/tempfile/tempfile_verify_test.go index 5feeeac18..d130d3e7a 100644 --- a/internal/tempfile/tempfile_verify_test.go +++ b/internal/tempfile/tempfile_verify_test.go @@ -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 { diff --git a/internal/uitask/uitask_test.go b/internal/uitask/uitask_test.go index 033ff2ddd..edc4d959b 100644 --- a/internal/uitask/uitask_test.go +++ b/internal/uitask/uitask_test.go @@ -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, diff --git a/internal/user/password_hashings_test.go b/internal/user/password_hashings_test.go index 590903de3..0c57318c9 100644 --- a/internal/user/password_hashings_test.go +++ b/internal/user/password_hashings_test.go @@ -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} { diff --git a/notification/sender/jsonsender/jsonsender_test.go b/notification/sender/jsonsender/jsonsender_test.go index 80ea05671..c5ec927c0 100644 --- a/notification/sender/jsonsender/jsonsender_test.go +++ b/notification/sender/jsonsender/jsonsender_test.go @@ -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)) diff --git a/notification/sender/pushover/pushover_sender_test.go b/notification/sender/pushover/pushover_sender_test.go index a3c78308a..2c1a3275f 100644 --- a/notification/sender/pushover/pushover_sender_test.go +++ b/notification/sender/pushover/pushover_sender_test.go @@ -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) diff --git a/notification/sender/testsender/test_sender_test.go b/notification/sender/testsender/test_sender_test.go index 9d0fb5c9d..13d3584f0 100644 --- a/notification/sender/testsender/test_sender_test.go +++ b/notification/sender/testsender/test_sender_test.go @@ -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", } diff --git a/notification/sender/webhook/webhook_sender_test.go b/notification/sender/webhook/webhook_sender_test.go index ae9a4dcfd..40d64b410 100644 --- a/notification/sender/webhook/webhook_sender_test.go +++ b/notification/sender/webhook/webhook_sender_test.go @@ -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) diff --git a/repo/blob/gcs/gcs_versioned_test.go b/repo/blob/gcs/gcs_versioned_test.go index 70e097198..f30349284 100644 --- a/repo/blob/gcs/gcs_versioned_test.go +++ b/repo/blob/gcs/gcs_versioned_test.go @@ -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)) diff --git a/repo/blob/s3/s3_versioned_test.go b/repo/blob/s3/s3_versioned_test.go index b337f6304..96f8a3720 100644 --- a/repo/blob/s3/s3_versioned_test.go +++ b/repo/blob/s3/s3_versioned_test.go @@ -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++ } } diff --git a/repo/blob/sftp/sftp_storage_test.go b/repo/blob/sftp/sftp_storage_test.go index 46862d0b4..77f07a780 100644 --- a/repo/blob/sftp/sftp_storage_test.go +++ b/repo/blob/sftp/sftp_storage_test.go @@ -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, diff --git a/repo/blob/storage_test.go b/repo/blob/storage_test.go index 39beaf7bd..a91b1bdaf 100644 --- a/repo/blob/storage_test.go +++ b/repo/blob/storage_test.go @@ -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 diff --git a/repo/blob/webdav/webdav_storage_test.go b/repo/blob/webdav/webdav_storage_test.go index 4c4fd6909..e9ec4e816 100644 --- a/repo/blob/webdav/webdav_storage_test.go +++ b/repo/blob/webdav/webdav_storage_test.go @@ -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) } diff --git a/repo/content/content_index_recovery_test.go b/repo/content/content_index_recovery_test.go index 18b95224e..9fe56543b 100644 --- a/repo/content/content_index_recovery_test.go +++ b/repo/content/content_index_recovery_test.go @@ -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 { diff --git a/repo/content/content_manager_test.go b/repo/content/content_manager_test.go index 3f4f785c7..ee703db78 100644 --- a/repo/content/content_manager_test.go +++ b/repo/content/content_manager_test.go @@ -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 { diff --git a/repo/content/index/merged_test.go b/repo/content/index/merged_test.go index e22d419ce..609980cf8 100644 --- a/repo/content/index/merged_test.go +++ b/repo/content/index/merged_test.go @@ -54,6 +54,7 @@ func TestMerged(t *testing.T) { t.Errorf("iteration preferred deleted content over non-deleted") } } + return nil })) diff --git a/repo/content/index/packindex_test.go b/repo/content/index/packindex_test.go index 210563c8e..dd29b0585 100644 --- a/repo/content/index/packindex_test.go +++ b/repo/content/index/packindex_test.go @@ -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 }) }) diff --git a/repo/content/indexblob/index_blob_manager_v0_test.go b/repo/content/indexblob/index_blob_manager_v0_test.go index cba55d17a..d76296509 100644 --- a/repo/content/indexblob/index_blob_manager_v0_test.go +++ b/repo/content/indexblob/index_blob_manager_v0_test.go @@ -569,6 +569,7 @@ func undeleteFakeContents(ctx context.Context, t *testing.T, m *ManagerV0, delet } delete(deleted, n) + count-- } diff --git a/repo/format/upgrade_lock_test.go b/repo/format/upgrade_lock_test.go index fb354b7d8..384f5ebcc 100644 --- a/repo/format/upgrade_lock_test.go +++ b/repo/format/upgrade_lock_test.go @@ -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 }, )) diff --git a/repo/maintenance/content_rewrite_test.go b/repo/maintenance/content_rewrite_test.go index e7e02b8ce..726118216 100644 --- a/repo/maintenance/content_rewrite_test.go +++ b/repo/maintenance/content_rewrite_test.go @@ -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 })) } diff --git a/repo/maintenance/maintenance_quick_test.go b/repo/maintenance/maintenance_quick_test.go index 428c0356a..82f666c0c 100644 --- a/repo/maintenance/maintenance_quick_test.go +++ b/repo/maintenance/maintenance_quick_test.go @@ -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) diff --git a/repo/maintenance/maintenance_safety_test.go b/repo/maintenance/maintenance_safety_test.go index ccd34c96e..05256c7f2 100644 --- a/repo/maintenance/maintenance_safety_test.go +++ b/repo/maintenance/maintenance_safety_test.go @@ -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 })) } diff --git a/repo/object/object_manager_test.go b/repo/object/object_manager_test.go index 0efc4e19d..bad35e5e9 100644 --- a/repo/object/object_manager_test.go +++ b/repo/object/object_manager_test.go @@ -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) } } diff --git a/repo/repository_test.go b/repo/repository_test.go index 5c410c332..c781f0387 100644 --- a/repo/repository_test.go +++ b/repo/repository_test.go @@ -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 })) } diff --git a/snapshot/policy/policy_manager_test.go b/snapshot/policy/policy_manager_test.go index 5eaa0dc71..ada82e93d 100644 --- a/snapshot/policy/policy_manager_test.go +++ b/snapshot/policy/policy_manager_test.go @@ -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) diff --git a/snapshot/policy/retention_policy_test.go b/snapshot/policy/retention_policy_test.go index 6a168e04c..a37ff611e 100644 --- a/snapshot/policy/retention_policy_test.go +++ b/snapshot/policy/retention_policy_test.go @@ -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) diff --git a/snapshot/snapshotfs/snapshot_verifier_test.go b/snapshot/snapshotfs/snapshot_verifier_test.go index 5febd4371..afbfccc80 100644 --- a/snapshot/snapshotfs/snapshot_verifier_test.go +++ b/snapshot/snapshotfs/snapshot_verifier_test.go @@ -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 })) diff --git a/snapshot/snapshotmaintenance/snapshotmaintenance_test.go b/snapshot/snapshotmaintenance/snapshotmaintenance_test.go index 68eee9f39..2e37fa58a 100644 --- a/snapshot/snapshotmaintenance/snapshotmaintenance_test.go +++ b/snapshot/snapshotmaintenance/snapshotmaintenance_test.go @@ -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) })) diff --git a/snapshot/upload/upload_estimator_test.go b/snapshot/upload/upload_estimator_test.go index 8125a32b2..5eb31decc 100644 --- a/snapshot/upload/upload_estimator_test.go +++ b/snapshot/upload/upload_estimator_test.go @@ -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{}) diff --git a/snapshot/upload/upload_test.go b/snapshot/upload/upload_test.go index 849deff20..4945daccd 100644 --- a/snapshot/upload/upload_test.go +++ b/snapshot/upload/upload_test.go @@ -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 } diff --git a/tests/end_to_end_test/auto_update_test.go b/tests/end_to_end_test/auto_update_test.go index 7b4c1375e..481eb1655 100644 --- a/tests/end_to_end_test/auto_update_test.go +++ b/tests/end_to_end_test/auto_update_test.go @@ -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() diff --git a/tests/end_to_end_test/compression_test.go b/tests/end_to_end_test/compression_test.go index 570b66da3..99d320821 100644 --- a/tests/end_to_end_test/compression_test.go +++ b/tests/end_to_end_test/compression_test.go @@ -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 } } diff --git a/tests/end_to_end_test/ecc_test.go b/tests/end_to_end_test/ecc_test.go index 5808c696d..8f095ca2f 100644 --- a/tests/end_to_end_test/ecc_test.go +++ b/tests/end_to_end_test/ecc_test.go @@ -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 }) diff --git a/tests/end_to_end_test/repository_connect_test.go b/tests/end_to_end_test/repository_connect_test.go index ff218c070..fd54fff93 100644 --- a/tests/end_to_end_test/repository_connect_test.go +++ b/tests/end_to_end_test/repository_connect_test.go @@ -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" diff --git a/tests/end_to_end_test/restore_test.go b/tests/end_to_end_test/restore_test.go index a106e7976..c4828b37c 100644 --- a/tests/end_to_end_test/restore_test.go +++ b/tests/end_to_end_test/restore_test.go @@ -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) diff --git a/tests/end_to_end_test/shallowrestore_test.go b/tests/end_to_end_test/shallowrestore_test.go index 4fbca7f97..c663b3ddb 100644 --- a/tests/end_to_end_test/shallowrestore_test.go +++ b/tests/end_to_end_test/shallowrestore_test.go @@ -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) diff --git a/tests/end_to_end_test/snapshot_actions_test.go b/tests/end_to_end_test/snapshot_actions_test.go index cfc0d565e..1cfc7d8fd 100644 --- a/tests/end_to_end_test/snapshot_actions_test.go +++ b/tests/end_to_end_test/snapshot_actions_test.go @@ -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) diff --git a/tests/end_to_end_test/snapshot_create_test.go b/tests/end_to_end_test/snapshot_create_test.go index 15057991c..400ab9b93 100644 --- a/tests/end_to_end_test/snapshot_create_test.go +++ b/tests/end_to_end_test/snapshot_create_test.go @@ -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) } diff --git a/tests/endurance_test/endurance_test.go b/tests/endurance_test/endurance_test.go index 735cf38b6..599fe1238 100644 --- a/tests/endurance_test/endurance_test.go +++ b/tests/endurance_test/endurance_test.go @@ -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) diff --git a/tests/htmlui_e2e_test/context_test.go b/tests/htmlui_e2e_test/context_test.go index 884d95d7b..350324f60 100644 --- a/tests/htmlui_e2e_test/context_test.go +++ b/tests/htmlui_e2e_test/context_test.go @@ -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 }) } diff --git a/tests/htmlui_e2e_test/htmlui_e2e_test.go b/tests/htmlui_e2e_test/htmlui_e2e_test.go index 7e8854de2..62c2e017c 100644 --- a/tests/htmlui_e2e_test/htmlui_e2e_test.go +++ b/tests/htmlui_e2e_test/htmlui_e2e_test.go @@ -335,6 +335,7 @@ func TestByteRepresentation(t *testing.T) { snap1Path := testutil.TempDirectory(t) var base2 string + var base10 string // create a test snaphot diff --git a/tests/repository_stress_test/repository_stress_test.go b/tests/repository_stress_test/repository_stress_test.go index 52171ff44..dbe01b9ca 100644 --- a/tests/repository_stress_test/repository_stress_test.go +++ b/tests/repository_stress_test/repository_stress_test.go @@ -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) diff --git a/tests/robustness/checker/checker.go b/tests/robustness/checker/checker.go index b04c8409e..08bc2ccbb 100644 --- a/tests/robustness/checker/checker.go +++ b/tests/robustness/checker/checker.go @@ -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++ } diff --git a/tests/robustness/engine/engine_test.go b/tests/robustness/engine/engine_test.go index f6c39a39c..05a8814c5 100644 --- a/tests/robustness/engine/engine_test.go +++ b/tests/robustness/engine/engine_test.go @@ -160,6 +160,7 @@ func makeTempS3Bucket(t *testing.T) (bucketName string, cleanupCB func()) { break } } + require.NoError(t, err) } } diff --git a/tests/robustness/multiclient_test/framework/harness.go b/tests/robustness/multiclient_test/framework/harness.go index bf66ed0c4..0c7d7662e 100644 --- a/tests/robustness/multiclient_test/framework/harness.go +++ b/tests/robustness/multiclient_test/framework/harness.go @@ -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. diff --git a/tests/robustness/multiclient_test/main_test.go b/tests/robustness/multiclient_test/main_test.go index 991a753ca..a0b59e762 100644 --- a/tests/robustness/multiclient_test/main_test.go +++ b/tests/robustness/multiclient_test/main_test.go @@ -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()) diff --git a/tests/robustness/multiclient_test/multiclient_test.go b/tests/robustness/multiclient_test/multiclient_test.go index 5b822b96e..08304caac 100644 --- a/tests/robustness/multiclient_test/multiclient_test.go +++ b/tests/robustness/multiclient_test/multiclient_test.go @@ -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, diff --git a/tests/robustness/multiclient_test/storagestats/storage_stats.go b/tests/robustness/multiclient_test/storagestats/storage_stats.go index 318e08a67..f1faf605b 100644 --- a/tests/robustness/multiclient_test/storagestats/storage_stats.go +++ b/tests/robustness/multiclient_test/storagestats/storage_stats.go @@ -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 }) diff --git a/tests/robustness/snapmeta/kopia_persister_light.go b/tests/robustness/snapmeta/kopia_persister_light.go index 241358322..f223d6ab0 100644 --- a/tests/robustness/snapmeta/kopia_persister_light.go +++ b/tests/robustness/snapmeta/kopia_persister_light.go @@ -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 diff --git a/tests/tools/fio/workload.go b/tests/tools/fio/workload.go index ecce6e42b..ab6b21330 100644 --- a/tests/tools/fio/workload.go +++ b/tests/tools/fio/workload.go @@ -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