golangci-lint: use exclude-rules instead of skip-files and skip-dirs

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL
2024-03-27 20:17:34 +00:00
parent 3c704ba1b1
commit ef04ef6361
69 changed files with 39 additions and 117 deletions
+2 -2
View File
@@ -154,8 +154,8 @@ func TestBackupProgressIsUpdated(t *testing.T) {
h.backupper.Backup(h.log, req, backupFile, nil, nil)
require.NotNil(t, req.Status.Progress)
assert.Equal(t, len(req.BackedUpItems), req.Status.Progress.TotalItems)
assert.Equal(t, len(req.BackedUpItems), req.Status.Progress.ItemsBackedUp)
assert.Len(t, req.BackedUpItems, req.Status.Progress.TotalItems)
assert.Len(t, req.BackedUpItems, req.Status.Progress.ItemsBackedUp)
}
// TestBackupResourceFiltering runs backups with different combinations
-1
View File
@@ -76,5 +76,4 @@ func TestSortOrderedResource(t *testing.T) {
}
sortedPvResources := sortResourcesByOrder(log, pvResources, pvOrder)
assert.Equal(t, sortedPvResources, expectedPvResources)
}
@@ -136,7 +136,6 @@ func TestRemapCRDVersionAction(t *testing.T) {
// set it back to the default one
a.discoveryHelper = fakeDiscoveryHelper()
})
}
// TestRemapCRDVersionActionData tests the RemapCRDVersionAction plugin against actual CRD to confirm that the v1beta1 version is returned when the v1 version is passed in to the plugin.
@@ -217,7 +216,6 @@ func TestRemapCRDVersionActionData(t *testing.T) {
betaClient.Delete(context.TODO(), crd.Name, metav1.DeleteOptions{})
})
}
}
func fakeDiscoveryHelper() velerodiscovery.Helper {
@@ -400,7 +400,6 @@ func TestServiceAccountActionExecute(t *testing.T) {
assert.Equal(t, test.expectedAdditionalItems, additional)
})
}
}
func TestServiceAccountActionExecuteOnBeta1(t *testing.T) {
@@ -608,5 +607,4 @@ func TestServiceAccountActionExecuteOnBeta1(t *testing.T) {
assert.Equal(t, test.expectedAdditionalItems, additional)
})
}
}
-1
View File
@@ -49,5 +49,4 @@ func TestFormattedGitSHA(t *testing.T) {
assert.Equal(t, FormattedGitSHA(), test.expected)
})
}
}
-1
View File
@@ -48,7 +48,6 @@ func removeConfigfileName() error {
return nil
}
func TestConfigOperations(t *testing.T) {
preHomeEnv := ""
prevEnv := os.Environ()
for _, entry := range prevEnv {
-2
View File
@@ -148,7 +148,6 @@ func TestCreateOptions_OrderedResources(t *testing.T) {
"persistentvolumes": "pv1,pv2",
}
assert.Equal(t, orderedResources, expectedMixedResources)
}
func TestCreateCommand(t *testing.T) {
@@ -156,7 +155,6 @@ func TestCreateCommand(t *testing.T) {
args := []string{name}
t.Run("create a backup create command with full options except fromSchedule and wait, then run by create option", func(t *testing.T) {
// create a factory
f := &factorymocks.Factory{}
+2 -2
View File
@@ -77,7 +77,7 @@ func TestNewGetCommand(t *testing.T) {
i++
}
}
assert.Equal(t, len(args), i)
assert.Len(t, args, i)
}
d := NewGetCommand(f, "velero backup get")
@@ -98,6 +98,6 @@ func TestNewGetCommand(t *testing.T) {
i++
}
}
assert.Equal(t, len(args), i)
assert.Len(t, args, i)
}
}
@@ -35,7 +35,6 @@ import (
)
func TestNewDeleteCommand(t *testing.T) {
// create a factory
f := &factorymocks.Factory{}
kbclient := velerotest.NewFakeControllerRuntimeClient(t)
@@ -75,7 +74,6 @@ func TestNewDeleteCommand(t *testing.T) {
return
}
t.Fatalf("process ran with err %v, want backups by get()", err)
}
func TestDeleteFunctions(t *testing.T) {
//t.Run("create the other create command with fromSchedule option for Run() other branches", func(t *testing.T) {
-1
View File
@@ -59,7 +59,6 @@ func TestCreateCommand(t *testing.T) {
args := []string{name}
t.Run("create a backup create command with full options except fromSchedule and wait, then run by create option", func(t *testing.T) {
// create a factory
f := &factorymocks.Factory{}
+1 -1
View File
@@ -76,6 +76,6 @@ func TestNewGetCommand(t *testing.T) {
i++
}
}
require.Equal(t, len(args), i)
require.Len(t, args, i)
}
}
-1
View File
@@ -71,7 +71,6 @@ func TestSetOfMap(t *testing.T) {
assert.EqualValues(t, c.expected, m.Data())
})
}
}
func TestStringOfMap(t *testing.T) {
@@ -618,5 +618,4 @@ func TestDescribeDeleteBackupRequestsInSF(t *testing.T) {
assert.True(tt, reflect.DeepEqual(sd.output, tc.expect))
})
}
}
-2
View File
@@ -435,7 +435,6 @@ func TestDefaultBackupTTL(t *testing.T) {
)
t.Run(test.name, func(t *testing.T) {
apiServer := velerotest.NewAPIServer(t)
discoveryHelper, err := discovery.NewHelper(apiServer.DiscoveryClient, logger)
require.NoError(t, err)
@@ -1735,6 +1734,5 @@ func TestPatchResourceWorksWithStatus(t *testing.T) {
t.Error(cmp.Diff(fromCluster, tt.args.updated))
}
})
}
}
@@ -75,7 +75,6 @@ func defaultTestDbr() *velerov1api.DeleteBackupRequest {
}
func setupBackupDeletionControllerTest(t *testing.T, req *velerov1api.DeleteBackupRequest, objects ...runtime.Object) *backupDeletionControllerTestData {
var (
fakeClient = velerotest.NewFakeControllerRuntimeClient(t, append(objects, req)...)
volumeSnapshotter = &velerotest.FakeVolumeSnapshotter{SnapshotsTaken: sets.NewString()}
@@ -215,7 +214,6 @@ func TestBackupDeletionControllerReconcile(t *testing.T) {
})
t.Run("unable to find backup", func(t *testing.T) {
td := setupBackupDeletionControllerTest(t, defaultTestDbr())
_, err := td.controller.Reconcile(context.TODO(), td.req)
@@ -261,7 +259,6 @@ func TestBackupDeletionControllerReconcile(t *testing.T) {
assert.Equal(t, "cannot delete backup because backup storage location default is currently in read-only mode", res.Status.Errors[0])
})
t.Run("full delete, no errors", func(t *testing.T) {
input := defaultTestDbr()
// Clear out resource labels to make sure the controller adds them and does not
@@ -668,7 +665,6 @@ func TestBackupDeletionControllerReconcile(t *testing.T) {
err = td.fakeClient.Get(ctx, td.req.NamespacedName, res)
assert.True(t, apierrors.IsNotFound(err), "Expected not found error, but actual value of error: %v", err)
td.backupStore.AssertNotCalled(t, "DeleteBackup", mock.Anything)
})
t.Run("Expired request will not be deleted if the status is not processed", func(t *testing.T) {
@@ -690,7 +686,6 @@ func TestBackupDeletionControllerReconcile(t *testing.T) {
assert.Equal(t, "Processed", string(res.Status.Phase))
assert.Len(t, res.Status.Errors, 1)
assert.Equal(t, "backup not found", res.Status.Errors[0])
})
}
@@ -57,7 +57,6 @@ func mockBackupRepositoryCR() *velerov1api.BackupRepository {
MaintenanceFrequency: metav1.Duration{Duration: testMaintenanceFrequency},
},
}
}
func TestPatchBackupRepository(t *testing.T) {
@@ -526,7 +526,6 @@ func TestOnDataDownloadCompleted(t *testing.T) {
ep := exposermockes.NewGenericRestoreExposer(t)
if test.rebindVolumeErr {
ep.On("RebindVolume", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(errors.New("Error to rebind volume"))
} else {
ep.On("RebindVolume", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
}
@@ -813,7 +812,6 @@ func TestTryCancelDataDownload(t *testing.T) {
}
func TestUpdateDataDownloadWithRetry(t *testing.T) {
namespacedName := types.NamespacedName{
Name: dataDownloadName,
Namespace: "velero",
@@ -1026,7 +1024,7 @@ func TestAttemptDataDownloadResume(t *testing.T) {
} else {
assert.NoError(t, err)
// Verify DataDownload marked as Cancelled
// Verify DataDownload marked as Canceled
for _, duName := range test.cancelledDataDownloads {
dataUpload := &velerov2alpha1api.DataDownload{}
err := r.client.Get(context.Background(), types.NamespacedName{Namespace: "velero", Name: duName}, dataUpload)
@@ -885,7 +885,6 @@ func TestTryCancelDataUpload(t *testing.T) {
}
func TestUpdateDataUploadWithRetry(t *testing.T) {
namespacedName := types.NamespacedName{
Name: dataUploadName,
Namespace: "velero",
@@ -1097,7 +1096,7 @@ func TestAttemptDataUploadResume(t *testing.T) {
} else {
assert.NoError(t, err)
// Verify DataUploads marked as Cancelled
// Verify DataUploads marked as Canceled
for _, duName := range test.cancelledDataUploads {
dataUpload := &velerov2alpha1api.DataUpload{}
err := r.client.Get(context.Background(), types.NamespacedName{Namespace: "velero", Name: duName}, dataUpload)
@@ -53,7 +53,6 @@ import (
)
func TestFetchBackupInfo(t *testing.T) {
tests := []struct {
name string
backupName string
@@ -206,7 +205,6 @@ func TestProcessQueueItemSkips(t *testing.T) {
}
func TestRestoreReconcile(t *testing.T) {
defaultStorageLocation := builder.ForBackupStorageLocation("velero", "default").Provider("myCloud").Bucket("bucket").Result()
now, err := time.Parse(time.RFC1123Z, time.RFC1123Z)
@@ -178,7 +178,6 @@ func TestRestoreFinalizerReconcile(t *testing.T) {
}
})
}
}
func TestUpdateResult(t *testing.T) {
@@ -453,7 +452,6 @@ func TestPatchDynamicPVWithVolumeInfo(t *testing.T) {
assert.Equal(t, expectedPVInfo.ReclaimPolicy, string(pv.Spec.PersistentVolumeReclaimPolicy))
assert.Equal(t, expectedPVInfo.Labels, pv.Labels)
}
}
}
@@ -489,5 +487,4 @@ func TestGetRestoredPVCFromRestoredResourceList(t *testing.T) {
}
actual = getRestoredPVCFromRestoredResourceList(restoredResourceList)
assert.Equal(t, expected, actual)
}
-1
View File
@@ -440,7 +440,6 @@ func TestExpose(t *testing.T) {
} else {
assert.EqualError(t, err, test.err)
}
})
}
}
-1
View File
@@ -1142,7 +1142,6 @@ func TestGetBackupVolumeInfos(t *testing.T) {
if len(tc.expectedResult) > 0 {
require.Equal(t, tc.expectedResult, result)
}
})
}
}
@@ -51,7 +51,6 @@ func TestNewClientBuilder(t *testing.T) {
assert.Equal(t, []string{"run-plugins", "--log-level", "info", "--features", "feature1,feature2"}, cb.commandArgs)
// Clear the features list in case other tests run in the same process.
features.NewFeatureFlagSet()
}
func TestClientConfig(t *testing.T) {
+1 -3
View File
@@ -197,7 +197,6 @@ func Test_backupper_BackupPodVolumes_log_test(t *testing.T) {
b.BackupPodVolumes(tt.args.backup, tt.args.pod, tt.args.volumesToBackup, tt.args.resPolicies, log)
fmt.Println(logOutput.String())
assert.Contains(t, logOutput.String(), tt.wantLog)
})
}
}
@@ -495,7 +494,7 @@ func TestBackupPodVolumes(t *testing.T) {
bsl: "fake-bsl",
},
{
name: "context cancelled",
name: "context canceled",
ctx: ctxWithCancel,
volumes: []string{
"fake-volume-1",
@@ -616,7 +615,6 @@ func TestBackupPodVolumes(t *testing.T) {
for _, pvb := range test.retPVBs {
bp.(*backupper).results[resultsKey(test.sourcePod.Namespace, test.sourcePod.Name)] <- pvb
}
}
}()
-1
View File
@@ -409,7 +409,6 @@ func TestRestorePodVolumes(t *testing.T) {
for _, pvr := range test.retPVRs {
rs.(*restorer).results[resultsKey(test.restoredPod.Namespace, test.restoredPod.Name)] <- pvr
}
}
}()
-1
View File
@@ -298,6 +298,5 @@ func TestVolumeHasNonRestorableSource(t *testing.T) {
actual := volumeHasNonRestorableSource(tc.volumeName, tc.podVolumes)
assert.Equal(t, tc.expected, actual)
})
}
}
+1 -1
View File
@@ -1000,7 +1000,7 @@ func TestBatchForget(t *testing.T) {
})
if tc.expectedErr == nil {
assert.Equal(t, 0, len(errs))
assert.Empty(t, errs)
} else {
assert.Equal(t, len(tc.expectedErr), len(errs))
-1
View File
@@ -89,7 +89,6 @@ func TestGetSnapshotCommand(t *testing.T) {
assert.Equal(t, expectedFlags, actualFlags)
assert.Equal(t, expectedTags, actualTags)
}
func TestInitCommand(t *testing.T) {
@@ -361,7 +361,6 @@ func TestMergeMaps(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := mergeMaps(tc.destination, tc.source)
assert.Equal(t, tc.expected, result)
-3
View File
@@ -1859,7 +1859,6 @@ func TestRestoreWithAsyncOperations(t *testing.T) {
UpdatedItem: obj,
OperationID: obj.GetName() + "-1",
}, nil
},
progressFunc: func(operationID string, restore *velerov1api.Restore) (velero.OperationProgress, error) {
return velero.OperationProgress{
@@ -1881,7 +1880,6 @@ func TestRestoreWithAsyncOperations(t *testing.T) {
UpdatedItem: obj,
OperationID: obj.GetName() + "-1",
}, nil
},
progressFunc: func(operationID string, restore *velerov1api.Restore) (velero.OperationProgress, error) {
return velero.OperationProgress{
@@ -1902,7 +1900,6 @@ func TestRestoreWithAsyncOperations(t *testing.T) {
return &velero.RestoreItemActionExecuteOutput{
UpdatedItem: obj,
}, nil
},
}
-1
View File
@@ -65,7 +65,6 @@ func svcJSONFromUnstructured(ports ...map[string]interface{}) string {
}
func TestServiceActionExecute(t *testing.T) {
tests := []struct {
name string
obj corev1api.Service
-1
View File
@@ -79,7 +79,6 @@ func MockFuncs(s *snapshotMockes, args []mockArgs) {
}
func TestSnapshotSource(t *testing.T) {
ctx := context.TODO()
sourceInfo := snapshot.SourceInfo{
UserName: "testUserName",
+1 -1
View File
@@ -228,7 +228,7 @@ func TestCheckContext(t *testing.T) {
kp.CheckContext(ctx, tc.finishChan, tc.restoreChan, tc.uploader)
if tc.expectCancel && tc.uploader != nil {
t.Error("Expected the uploader to be cancelled")
t.Error("Expected the uploader to be canceled")
}
if tc.expectBackup && tc.uploader == nil && len(tc.restoreChan) > 0 {
-1
View File
@@ -85,7 +85,6 @@ func TestNewUploaderProvider(t *testing.T) {
mockFileGetter := &mocks.FileStore{}
mockFileGetter.On("Path", &v1.SecretKeySelector{}).Return("", nil)
credGetter.FromFile = mockFileGetter
}
_, err := NewUploaderProvider(ctx, client, testCase.UploaderType, testCase.RequestorType, repoIdentifier, bsl, backupRepo, credGetter, repoKeySelector, log)
if testCase.ExpectedError == "" {
-1
View File
@@ -232,7 +232,6 @@ func TestResticRunRestore(t *testing.T) {
require.Equal(t, true, tc.errorHandleFunc(err))
})
}
}
func TestClose(t *testing.T) {
-1
View File
@@ -47,7 +47,6 @@ func TestNewCredential(t *testing.T) {
}
_, err = NewCredential(creds, options)
require.Nil(t, err)
}
func Test_newConfigCredential(t *testing.T) {
@@ -729,7 +729,6 @@ func TestGetScopedResourceIncludesExcludes(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
logger := logrus.StandardLogger()
nsIncludeExclude := NewIncludesExcludes()
resources := GetScopeResourceIncludesExcludes(setupDiscoveryClientWithResources(tc.apiResources), logger, tc.namespaceScopedIncludes, tc.namespaceScopedExcludes, tc.clusterScopedIncludes, tc.clusterScopedExcludes, *nsIncludeExclude)
-1
View File
@@ -25,7 +25,6 @@ import (
)
func TestCSIFeatureNotEnabledAndPluginIsFromCSI(t *testing.T) {
features.NewFeatureFlagSet("EnableCSI")
require.False(t, ShouldSkipAction("abc"))
require.False(t, ShouldSkipAction("velero.io/csi-pvc-backupper"))
-1
View File
@@ -138,7 +138,6 @@ func TestEnsureNamespaceExistsAndIsReady(t *testing.T) {
assert.Equal(t, test.expectedCreatedResult, nsCreated)
})
}
}
// TestGetVolumeDirectorySuccess tests that the GetVolumeDirectory function