Skip to content

Commit

Permalink
golangci-lint: use exclude-rules instead of skip-files and skip-dirs
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Mar 27, 2024
1 parent 3c704ba commit ef04ef6
Show file tree
Hide file tree
Showing 69 changed files with 39 additions and 117 deletions.
41 changes: 29 additions & 12 deletions golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,12 @@ run:
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-dirs:
- test/*
- pkg/plugin/generated/*
# - autogenerated_by_my_lib

# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-files:
- ".*_test.go$"
# - lib/bad.go

# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
Expand Down Expand Up @@ -364,6 +352,35 @@ issues:
- linters:
- staticcheck
text: "DefaultVolumesToRestic" # No need to report deprecate for DefaultVolumesToRestic.
- path: ".*_test.go$"
linters:
- dupword
- errcheck
- ginkgolinter
- goconst
- gosec
- govet
- staticcheck
- stylecheck
- unconvert
- unparam
- unused
- path: test/
linters:
- bodyclose
- dupword
- errcheck
- goconst
- gosec
- gosimple
- ginkgolinter
- nilerr
- noctx
- staticcheck
- stylecheck
- unconvert
- unparam
- unused

# The list of ids of default excludes to include or disable. By default it's empty.
include:
Expand Down
1 change: 0 additions & 1 deletion internal/hook/hook_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func TestHookTracker_Record(t *testing.T) {

err = tracker.Record("ns2", "pod2", "container1", HookSourceAnnotation, "h1", PhasePre, true)
assert.NotNil(t, err)

}

func TestHookTracker_Stat(t *testing.T) {
Expand Down
2 changes: 0 additions & 2 deletions internal/hook/item_hook_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2351,14 +2351,12 @@ func TestBackupHookTracker(t *testing.T) {
}
}
h.HandleHooks(velerotest.NewLogger(), groupResource, pod.item, pod.hooks, test.phase, hookTracker)

}
actualAtemptted, actualFailed := hookTracker.Stat()
assert.Equal(t, test.expectedHookAttempted, actualAtemptted)
assert.Equal(t, test.expectedHookFailed, actualFailed)
})
}

}

func TestRestoreHookTrackerAdd(t *testing.T) {
Expand Down
2 changes: 0 additions & 2 deletions internal/hook/wait_exec_hook_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,6 @@ func TestWaitExecHandleHooks(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {

source := fcache.NewFakeControllerSource()
go func() {
// This is the state of the pod that will be seen by the AddFunc handler.
Expand Down Expand Up @@ -1251,7 +1250,6 @@ func TestRestoreHookTrackerUpdate(t *testing.T) {

for _, test := range tests1 {
t.Run(test.name, func(t *testing.T) {

source := fcache.NewFakeControllerSource()
go func() {
// This is the state of the pod that will be seen by the AddFunc handler.
Expand Down
1 change: 0 additions & 1 deletion internal/resourcemodifiers/resource_modifiers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ func TestGetResourceModifiersFromConfig(t *testing.T) {
}

func TestResourceModifiers_ApplyResourceModifierRules(t *testing.T) {

pvcStandardSc := &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "v1",
Expand Down
3 changes: 0 additions & 3 deletions internal/resourcepolicies/volume_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func TestCapacityIsInRange(t *testing.T) {
actual := test.capacity.isInRange(test.quantity)

assert.Equal(t, test.isInRange, actual)

})
}
}
Expand Down Expand Up @@ -141,7 +140,6 @@ func TestStorageClassConditionMatch(t *testing.T) {
}

func TestNFSConditionMatch(t *testing.T) {

tests := []struct {
name string
condition *nfsCondition
Expand Down Expand Up @@ -196,7 +194,6 @@ func TestNFSConditionMatch(t *testing.T) {
}

func TestCSIConditionMatch(t *testing.T) {

tests := []struct {
name string
condition *csiCondition
Expand Down
1 change: 0 additions & 1 deletion internal/velero/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func testDefaultImage(t *testing.T, defaultImageFn func() string, imageName stri
assert.Equal(t, tc.want, defaultImageFn())
})
}

}

func TestDefaultVeleroImage(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion pkg/backup/item_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,4 @@ func TestSortOrderedResource(t *testing.T) {
}
sortedPvResources := sortResourcesByOrder(log, pvResources, pvOrder)
assert.Equal(t, sortedPvResources, expectedPvResources)

}
2 changes: 0 additions & 2 deletions pkg/backup/remap_crd_version_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -217,7 +216,6 @@ func TestRemapCRDVersionActionData(t *testing.T) {
betaClient.Delete(context.TODO(), crd.Name, metav1.DeleteOptions{})
})
}

}

func fakeDiscoveryHelper() velerodiscovery.Helper {
Expand Down
2 changes: 0 additions & 2 deletions pkg/backup/service_account_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ func TestServiceAccountActionExecute(t *testing.T) {
assert.Equal(t, test.expectedAdditionalItems, additional)
})
}

}

func TestServiceAccountActionExecuteOnBeta1(t *testing.T) {
Expand Down Expand Up @@ -608,5 +607,4 @@ func TestServiceAccountActionExecuteOnBeta1(t *testing.T) {
assert.Equal(t, test.expectedAdditionalItems, additional)
})
}

}
1 change: 0 additions & 1 deletion pkg/buildinfo/buildinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,4 @@ func TestFormattedGitSHA(t *testing.T) {
assert.Equal(t, FormattedGitSHA(), test.expected)
})
}

}
1 change: 0 additions & 1 deletion pkg/client/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func removeConfigfileName() error {
return nil
}
func TestConfigOperations(t *testing.T) {

preHomeEnv := ""
prevEnv := os.Environ()
for _, entry := range prevEnv {
Expand Down
2 changes: 0 additions & 2 deletions pkg/cmd/cli/backup/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,13 @@ func TestCreateOptions_OrderedResources(t *testing.T) {
"persistentvolumes": "pv1,pv2",
}
assert.Equal(t, orderedResources, expectedMixedResources)

}

func TestCreateCommand(t *testing.T) {
name := "nameToBeCreated"
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{}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/cli/backup/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -98,6 +98,6 @@ func TestNewGetCommand(t *testing.T) {
i++
}
}
assert.Equal(t, len(args), i)
assert.Len(t, args, i)
}
}
2 changes: 0 additions & 2 deletions pkg/cmd/cli/backuplocation/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
)

func TestNewDeleteCommand(t *testing.T) {

// create a factory
f := &factorymocks.Factory{}
kbclient := velerotest.NewFakeControllerRuntimeClient(t)
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/cli/restore/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/restore/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ func TestNewGetCommand(t *testing.T) {
i++
}
}
require.Equal(t, len(args), i)
require.Len(t, args, i)
}
}
1 change: 0 additions & 1 deletion pkg/cmd/util/flag/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func TestSetOfMap(t *testing.T) {
assert.EqualValues(t, c.expected, m.Data())
})
}

}

func TestStringOfMap(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/util/output/backup_structured_describer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,5 +618,4 @@ func TestDescribeDeleteBackupRequestsInSF(t *testing.T) {
assert.True(tt, reflect.DeepEqual(sd.output, tc.expect))
})
}

}
2 changes: 0 additions & 2 deletions pkg/controller/backup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1735,6 +1734,5 @@ func TestPatchResourceWorksWithStatus(t *testing.T) {
t.Error(cmp.Diff(fromCluster, tt.args.updated))
}
})

}
}
5 changes: 0 additions & 5 deletions pkg/controller/backup_deletion_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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])

})
}

Expand Down
1 change: 0 additions & 1 deletion pkg/controller/backup_repository_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func mockBackupRepositoryCR() *velerov1api.BackupRepository {
MaintenanceFrequency: metav1.Duration{Duration: testMaintenanceFrequency},
},
}

}

func TestPatchBackupRepository(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions pkg/controller/data_download_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -813,7 +812,6 @@ func TestTryCancelDataDownload(t *testing.T) {
}

func TestUpdateDataDownloadWithRetry(t *testing.T) {

namespacedName := types.NamespacedName{
Name: dataDownloadName,
Namespace: "velero",
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/data_upload_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,6 @@ func TestTryCancelDataUpload(t *testing.T) {
}

func TestUpdateDataUploadWithRetry(t *testing.T) {

namespacedName := types.NamespacedName{
Name: dataUploadName,
Namespace: "velero",
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit ef04ef6

Please sign in to comment.