Merge pull request #8314 from mmorel-35/golangci-lint/thelper
golangci-lint: enable and fix thelper linterpull/8322/head
commit
732b87b250
|
@ -314,6 +314,7 @@ linters:
|
||||||
- staticcheck
|
- staticcheck
|
||||||
- stylecheck
|
- stylecheck
|
||||||
- testifylint
|
- testifylint
|
||||||
|
- thelper
|
||||||
- typecheck
|
- typecheck
|
||||||
- unconvert
|
- unconvert
|
||||||
- unparam
|
- unparam
|
||||||
|
|
|
@ -75,6 +75,7 @@ func RunRestartableDelegateTests(
|
||||||
newMock func() Mockable,
|
newMock func() Mockable,
|
||||||
tests ...RestartableDelegateTest,
|
tests ...RestartableDelegateTest,
|
||||||
) {
|
) {
|
||||||
|
t.Helper()
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
t.Run(tc.Function, func(t *testing.T) {
|
t.Run(tc.Function, func(t *testing.T) {
|
||||||
p := new(MockRestartableProcess)
|
p := new(MockRestartableProcess)
|
||||||
|
|
|
@ -86,6 +86,7 @@ func TestImageRegistry(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testDefaultImage(t *testing.T, defaultImageFn func() string, imageName string) {
|
func testDefaultImage(t *testing.T, defaultImageFn func() string, imageName string) {
|
||||||
|
t.Helper()
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
buildInfoVersion string
|
buildInfoVersion string
|
||||||
|
|
|
@ -77,6 +77,7 @@ func defaultTestDbr() *velerov1api.DeleteBackupRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupBackupDeletionControllerTest(t *testing.T, req *velerov1api.DeleteBackupRequest, objects ...runtime.Object) *backupDeletionControllerTestData {
|
func setupBackupDeletionControllerTest(t *testing.T, req *velerov1api.DeleteBackupRequest, objects ...runtime.Object) *backupDeletionControllerTestData {
|
||||||
|
t.Helper()
|
||||||
var (
|
var (
|
||||||
fakeClient = velerotest.NewFakeControllerRuntimeClient(t, append(objects, req)...)
|
fakeClient = velerotest.NewFakeControllerRuntimeClient(t, append(objects, req)...)
|
||||||
volumeSnapshotter = &velerotest.FakeVolumeSnapshotter{SnapshotsTaken: sets.NewString()}
|
volumeSnapshotter = &velerotest.FakeVolumeSnapshotter{SnapshotsTaken: sets.NewString()}
|
||||||
|
|
|
@ -38,6 +38,7 @@ import (
|
||||||
const testMaintenanceFrequency = 10 * time.Minute
|
const testMaintenanceFrequency = 10 * time.Minute
|
||||||
|
|
||||||
func mockBackupRepoReconciler(t *testing.T, mockOn string, arg interface{}, ret interface{}) *BackupRepoReconciler {
|
func mockBackupRepoReconciler(t *testing.T, mockOn string, arg interface{}, ret interface{}) *BackupRepoReconciler {
|
||||||
|
t.Helper()
|
||||||
mgr := &repomokes.Manager{}
|
mgr := &repomokes.Manager{}
|
||||||
if mockOn != "" {
|
if mockOn != "" {
|
||||||
mgr.On(mockOn, arg).Return(ret)
|
mgr.On(mockOn, arg).Return(ret)
|
||||||
|
|
|
@ -282,6 +282,7 @@ func getPluginTest(
|
||||||
expectedResultFunc func(name string, sharedPluginProcess process.RestartableProcess) interface{},
|
expectedResultFunc func(name string, sharedPluginProcess process.RestartableProcess) interface{},
|
||||||
reinitializable bool,
|
reinitializable bool,
|
||||||
) {
|
) {
|
||||||
|
t.Helper()
|
||||||
logger := test.NewLogger()
|
logger := test.NewLogger()
|
||||||
logLevel := logrus.InfoLevel
|
logLevel := logrus.InfoLevel
|
||||||
|
|
||||||
|
|
|
@ -3576,6 +3576,7 @@ func Test_getOrderedResources(t *testing.T) {
|
||||||
// order. Any resources *not* in resourcePriorities are required to come *after* all
|
// order. Any resources *not* in resourcePriorities are required to come *after* all
|
||||||
// resources in any order.
|
// resources in any order.
|
||||||
func assertResourceCreationOrder(t *testing.T, resourcePriorities []string, createdResources []resourceID) {
|
func assertResourceCreationOrder(t *testing.T, resourcePriorities []string, createdResources []resourceID) {
|
||||||
|
t.Helper()
|
||||||
// lastSeen tracks the index in 'resourcePriorities' of the last resource type
|
// lastSeen tracks the index in 'resourcePriorities' of the last resource type
|
||||||
// we saw created. Once we've seen a resource in 'resourcePriorities', we should
|
// we saw created. Once we've seen a resource in 'resourcePriorities', we should
|
||||||
// never see another instance of a prior resource.
|
// never see another instance of a prior resource.
|
||||||
|
|
|
@ -39,6 +39,7 @@ import (
|
||||||
// corresponding expected Action, and that each expected Action
|
// corresponding expected Action, and that each expected Action
|
||||||
// has a corresponding actual Action.
|
// has a corresponding actual Action.
|
||||||
func CompareActions(t *testing.T, expected, actual []core.Action) {
|
func CompareActions(t *testing.T, expected, actual []core.Action) {
|
||||||
|
t.Helper()
|
||||||
assert.Len(t, actual, len(expected))
|
assert.Len(t, actual, len(expected))
|
||||||
|
|
||||||
for _, e := range expected {
|
for _, e := range expected {
|
||||||
|
@ -73,6 +74,7 @@ func CompareActions(t *testing.T, expected, actual []core.Action) {
|
||||||
// with the provided decode func and has no extraneous fields, and that
|
// with the provided decode func and has no extraneous fields, and that
|
||||||
// the decoded patch matches the expected.
|
// the decoded patch matches the expected.
|
||||||
func ValidatePatch(t *testing.T, action core.Action, expected interface{}, decodeFunc func(*json.Decoder) (interface{}, error)) {
|
func ValidatePatch(t *testing.T, action core.Action, expected interface{}, decodeFunc func(*json.Decoder) (interface{}, error)) {
|
||||||
|
t.Helper()
|
||||||
patchAction, ok := action.(core.PatchAction)
|
patchAction, ok := action.(core.PatchAction)
|
||||||
require.True(t, ok, "action is not a PatchAction")
|
require.True(t, ok, "action is not a PatchAction")
|
||||||
|
|
||||||
|
@ -96,6 +98,7 @@ func TimesAreEqual(t1, t2 time.Time) bool {
|
||||||
// This function exists in order to make sure time.Time and metav1.Time objects
|
// This function exists in order to make sure time.Time and metav1.Time objects
|
||||||
// can be compared correctly. See https://github.com/stretchr/testify/issues/502.
|
// can be compared correctly. See https://github.com/stretchr/testify/issues/502.
|
||||||
func AssertDeepEqual(t *testing.T, expected, actual interface{}) bool {
|
func AssertDeepEqual(t *testing.T, expected, actual interface{}) bool {
|
||||||
|
t.Helper()
|
||||||
// By default, the equality.Semantic object doesn't have a function for comparing time.Times
|
// By default, the equality.Semantic object doesn't have a function for comparing time.Times
|
||||||
err := equality.Semantic.AddFunc(TimesAreEqual)
|
err := equality.Semantic.AddFunc(TimesAreEqual)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -114,6 +117,7 @@ func AssertDeepEqual(t *testing.T, expected, actual interface{}) bool {
|
||||||
// AssertErrorMatches asserts that if expected is the empty string, actual
|
// AssertErrorMatches asserts that if expected is the empty string, actual
|
||||||
// is nil, otherwise, that actual's error string matches expected.
|
// is nil, otherwise, that actual's error string matches expected.
|
||||||
func AssertErrorMatches(t *testing.T, expected string, actual error) bool {
|
func AssertErrorMatches(t *testing.T, expected string, actual error) bool {
|
||||||
|
t.Helper()
|
||||||
if expected != "" {
|
if expected != "" {
|
||||||
return assert.EqualError(t, actual, expected)
|
return assert.EqualError(t, actual, expected)
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewFakeControllerRuntimeClientBuilder(t *testing.T) *k8sfake.ClientBuilder {
|
func NewFakeControllerRuntimeClientBuilder(t *testing.T) *k8sfake.ClientBuilder {
|
||||||
|
t.Helper()
|
||||||
scheme := runtime.NewScheme()
|
scheme := runtime.NewScheme()
|
||||||
|
|
||||||
require.NoError(t, velerov1api.AddToScheme(scheme))
|
require.NoError(t, velerov1api.AddToScheme(scheme))
|
||||||
|
@ -46,6 +47,7 @@ func NewFakeControllerRuntimeClientBuilder(t *testing.T) *k8sfake.ClientBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFakeControllerRuntimeClient(t *testing.T, initObjs ...runtime.Object) client.Client {
|
func NewFakeControllerRuntimeClient(t *testing.T, initObjs ...runtime.Object) client.Client {
|
||||||
|
t.Helper()
|
||||||
scheme := runtime.NewScheme()
|
scheme := runtime.NewScheme()
|
||||||
|
|
||||||
require.NoError(t, velerov1api.AddToScheme(scheme))
|
require.NoError(t, velerov1api.AddToScheme(scheme))
|
||||||
|
@ -62,5 +64,6 @@ func NewFakeControllerRuntimeWatchClient(
|
||||||
t *testing.T,
|
t *testing.T,
|
||||||
initObjs ...runtime.Object,
|
initObjs ...runtime.Object,
|
||||||
) client.WithWatch {
|
) client.WithWatch {
|
||||||
|
t.Helper()
|
||||||
return NewFakeControllerRuntimeClientBuilder(t).WithRuntimeObjects(initObjs...).Build()
|
return NewFakeControllerRuntimeClientBuilder(t).WithRuntimeObjects(initObjs...).Build()
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ type TarWriter struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTarWriter(t *testing.T) *TarWriter {
|
func NewTarWriter(t *testing.T) *TarWriter {
|
||||||
|
t.Helper()
|
||||||
tw := new(TarWriter)
|
tw := new(TarWriter)
|
||||||
tw.t = t
|
tw.t = t
|
||||||
tw.buf = new(bytes.Buffer)
|
tw.buf = new(bytes.Buffer)
|
||||||
|
|
Loading…
Reference in New Issue