From 2147683a57b59730846ac76ea8c39861c262217b Mon Sep 17 00:00:00 2001 From: "Kiss, Tibor" Date: Wed, 28 Feb 2024 13:55:09 +0100 Subject: [PATCH] Linter: thelper --- .golangci.yaml | 1 - .../controller/integration_test.go | 2 ++ internal/controller/nats/unit_test.go | 1 + pkg/k8s/chart/helmrenderer_test.go | 1 + pkg/manager/overrides_test.go | 1 + testutils/integration/integration.go | 27 +++++++++++++++++++ 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.golangci.yaml b/.golangci.yaml index 6575bfc3..b05da5a6 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -36,7 +36,6 @@ linters: - gomoddirectives - testifylint - containedctx - - thelper - tagliatelle - errchkjson - perfsprint diff --git a/internal/controller/nats/integrationtests/controller/integration_test.go b/internal/controller/nats/integrationtests/controller/integration_test.go index 7f02f763..aa8dc7c2 100644 --- a/internal/controller/nats/integrationtests/controller/integration_test.go +++ b/internal/controller/nats/integrationtests/controller/integration_test.go @@ -602,6 +602,7 @@ func Test_DoubleReconcileNATSCR(t *testing.T) { } func makeStatefulSetReady(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { sts, err := testEnvironment.GetStatefulSetFromK8s(name, namespace) if err != nil { @@ -629,6 +630,7 @@ type deletionFunc func(env integration.TestEnvironment, natsName, namespace stri func ensureK8sResourceDeletion( t *testing.T, env integration.TestEnvironment, natsName, namespace string, fs ...deletionFunc, ) { + t.Helper() for _, f := range fs { require.NoError(t, f(env, natsName, namespace)) } diff --git a/internal/controller/nats/unit_test.go b/internal/controller/nats/unit_test.go index e547eb22..a53b21e2 100644 --- a/internal/controller/nats/unit_test.go +++ b/internal/controller/nats/unit_test.go @@ -35,6 +35,7 @@ type MockedUnitTestEnvironment struct { } func NewMockedUnitTestEnvironment(t *testing.T, objs ...client.Object) *MockedUnitTestEnvironment { + t.Helper() // setup context ctx := context.Background() diff --git a/pkg/k8s/chart/helmrenderer_test.go b/pkg/k8s/chart/helmrenderer_test.go index 3ff6d734..35a7aa0b 100644 --- a/pkg/k8s/chart/helmrenderer_test.go +++ b/pkg/k8s/chart/helmrenderer_test.go @@ -204,6 +204,7 @@ func Test_RenderManifestAsUnstructured(t *testing.T) { } func loadHelmChart(t *testing.T) *chart.Chart { + t.Helper() helmChart, err := loader.Load(testChartDir) require.NoError(t, err) return helmChart diff --git a/pkg/manager/overrides_test.go b/pkg/manager/overrides_test.go index dbdc9e27..c753ef2d 100644 --- a/pkg/manager/overrides_test.go +++ b/pkg/manager/overrides_test.go @@ -169,6 +169,7 @@ func Test_Overrides_Keys(t *testing.T) { } func getValueFromNestedMap(t *testing.T, key string, data map[string]interface{}) interface{} { + t.Helper() tokens := strings.Split(key, ".") lastNestedData := data for depth, token := range tokens { diff --git a/testutils/integration/integration.go b/testutils/integration/integration.go index b9a0ffb0..432b30ca 100644 --- a/testutils/integration/integration.go +++ b/testutils/integration/integration.go @@ -207,6 +207,7 @@ func (env TestEnvironment) CreateK8sResource(obj client.Object) error { } func (env TestEnvironment) EnsureNamespaceCreation(t *testing.T, namespace string) { + t.Helper() if namespace == "default" { return } @@ -216,10 +217,12 @@ func (env TestEnvironment) EnsureNamespaceCreation(t *testing.T, namespace strin } func (env TestEnvironment) EnsureK8sResourceCreated(t *testing.T, obj client.Object) { + t.Helper() require.NoError(t, env.k8sClient.Create(env.Context, obj)) } func (env TestEnvironment) EnsureK8sUnStructResourceCreated(t *testing.T, obj *unstructured.Unstructured) { + t.Helper() require.NoError(t, env.k8sClient.Create(env.Context, obj)) } @@ -228,6 +231,7 @@ func (env TestEnvironment) CreateUnstructuredK8sResource(obj *unstructured.Unstr } func (env TestEnvironment) EnsureK8sResourceUpdated(t *testing.T, obj client.Object) { + t.Helper() require.NoError(t, env.k8sClient.Update(env.Context, obj)) } @@ -247,10 +251,12 @@ func (env TestEnvironment) UpdatedNATSInK8s(nats *nmapiv1alpha1.NATS, options .. } func (env TestEnvironment) EnsureK8sResourceDeleted(t *testing.T, obj client.Object) { + t.Helper() require.NoError(t, env.k8sClient.Delete(env.Context, obj)) } func (env TestEnvironment) EnsureK8sConfigMapExists(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetConfigMapFromK8s(name, namespace) return err == nil && result != nil @@ -258,6 +264,7 @@ func (env TestEnvironment) EnsureK8sConfigMapExists(t *testing.T, name, namespac } func (env TestEnvironment) EnsureK8sSecretExists(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetSecretFromK8s(name, namespace) return err == nil && result != nil @@ -265,6 +272,7 @@ func (env TestEnvironment) EnsureK8sSecretExists(t *testing.T, name, namespace s } func (env TestEnvironment) EnsureK8sPodDisruptionBudgetExists(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetPodDisruptionBudgetFromK8s(name, namespace) return err == nil && result != nil @@ -272,6 +280,7 @@ func (env TestEnvironment) EnsureK8sPodDisruptionBudgetExists(t *testing.T, name } func (env TestEnvironment) EnsureK8sServiceExists(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetServiceFromK8s(name, namespace) return err == nil && result != nil @@ -279,6 +288,7 @@ func (env TestEnvironment) EnsureK8sServiceExists(t *testing.T, name, namespace } func (env TestEnvironment) EnsureK8sDestinationRuleExists(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetDestinationRuleFromK8s(name, namespace) return err == nil && result != nil @@ -286,6 +296,7 @@ func (env TestEnvironment) EnsureK8sDestinationRuleExists(t *testing.T, name, na } func (env TestEnvironment) EnsureK8sStatefulSetExists(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetStatefulSetFromK8s(name, namespace) if err != nil { @@ -297,6 +308,7 @@ func (env TestEnvironment) EnsureK8sStatefulSetExists(t *testing.T, name, namesp } func (env TestEnvironment) EnsureK8sPVCExists(t *testing.T, label, namespace string) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetPVCFromK8s(label, namespace) if err != nil { @@ -308,6 +320,7 @@ func (env TestEnvironment) EnsureK8sPVCExists(t *testing.T, label, namespace str } func (env TestEnvironment) EnsureK8sConfigMapNotFound(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { _, err := env.GetConfigMapFromK8s(name, namespace) return err != nil && kapierrors.IsNotFound(err) @@ -315,6 +328,7 @@ func (env TestEnvironment) EnsureK8sConfigMapNotFound(t *testing.T, name, namesp } func (env TestEnvironment) EnsureK8sSecretNotFound(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { _, err := env.GetSecretFromK8s(name, namespace) return err != nil && kapierrors.IsNotFound(err) @@ -322,6 +336,7 @@ func (env TestEnvironment) EnsureK8sSecretNotFound(t *testing.T, name, namespace } func (env TestEnvironment) EnsureK8sServiceNotFound(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { _, err := env.GetServiceFromK8s(name, namespace) return err != nil && kapierrors.IsNotFound(err) @@ -329,6 +344,7 @@ func (env TestEnvironment) EnsureK8sServiceNotFound(t *testing.T, name, namespac } func (env TestEnvironment) EnsureK8sDestinationRuleNotFound(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { _, err := env.GetDestinationRuleFromK8s(name, namespace) return err != nil && kapierrors.IsNotFound(err) @@ -336,6 +352,7 @@ func (env TestEnvironment) EnsureK8sDestinationRuleNotFound(t *testing.T, name, } func (env TestEnvironment) EnsureK8sNATSNotFound(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { _, err := env.GetNATSFromK8s(name, namespace) return err != nil && kapierrors.IsNotFound(err) @@ -343,6 +360,7 @@ func (env TestEnvironment) EnsureK8sNATSNotFound(t *testing.T, name, namespace s } func (env TestEnvironment) EnsureK8sStatefulSetNotFound(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { _, err := env.GetStatefulSetFromK8s(name, namespace) if err != nil { @@ -354,6 +372,7 @@ func (env TestEnvironment) EnsureK8sStatefulSetNotFound(t *testing.T, name, name } func (env TestEnvironment) EnsureK8sPVCNotFound(t *testing.T, name, namespace string) { + t.Helper() require.Eventually(t, func() bool { pvc, err := env.GetPVCFromK8s(name, namespace) if err != nil { @@ -368,6 +387,7 @@ func (env TestEnvironment) EnsureK8sPVCNotFound(t *testing.T, name, namespace st func (env TestEnvironment) EnsureK8sStatefulSetHasLabels(t *testing.T, name, namespace string, labels map[string]string, ) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetStatefulSetFromK8s(name, namespace) if err != nil { @@ -389,6 +409,7 @@ func (env TestEnvironment) EnsureK8sStatefulSetHasLabels(t *testing.T, name, nam func (env TestEnvironment) EnsureK8sStatefulSetHasAnnotations(t *testing.T, name, namespace string, annotations map[string]string, ) { + t.Helper() require.Eventually(t, func() bool { result, err := env.GetStatefulSetFromK8s(name, namespace) if err != nil { @@ -410,6 +431,7 @@ func (env TestEnvironment) EnsureK8sStatefulSetHasAnnotations(t *testing.T, name // EnsureNATSSpecClusterSizeReflected ensures that NATS CR Spec.cluster.size is reflected // in relevant k8s objects. func (env TestEnvironment) EnsureNATSSpecClusterSizeReflected(t *testing.T, nats nmapiv1alpha1.NATS) { + t.Helper() require.Eventually(t, func() bool { stsName := testutils.GetStatefulSetName(nats) result, err := env.GetStatefulSetFromK8s(stsName, nats.Namespace) @@ -425,6 +447,7 @@ func (env TestEnvironment) EnsureNATSSpecClusterSizeReflected(t *testing.T, nats // EnsureNATSSpecResourcesReflected ensures that NATS CR Spec.resources is reflected // in relevant k8s objects. func (env TestEnvironment) EnsureNATSSpecResourcesReflected(t *testing.T, nats nmapiv1alpha1.NATS) { + t.Helper() require.Eventually(t, func() bool { stsName := testutils.GetStatefulSetName(nats) result, err := env.GetStatefulSetFromK8s(stsName, nats.Namespace) @@ -444,6 +467,7 @@ func (env TestEnvironment) EnsureNATSSpecResourcesReflected(t *testing.T, nats n // EnsureNATSSpecDebugTraceReflected ensures that NATS CR Spec.trace and Spec.debug is reflected // in relevant k8s objects. func (env TestEnvironment) EnsureNATSSpecDebugTraceReflected(t *testing.T, nats nmapiv1alpha1.NATS) { + t.Helper() require.Eventually(t, func() bool { // get NATS configMap. result, err := env.GetConfigMapFromK8s(testutils.GetConfigMapName(nats), nats.Namespace) @@ -468,6 +492,7 @@ func (env TestEnvironment) EnsureNATSSpecDebugTraceReflected(t *testing.T, nats // EnsureNATSSpecFileStorageReflected ensures that NATS CR Spec.jetStream.fileStorage is reflected // in relevant k8s objects. func (env TestEnvironment) EnsureNATSSpecFileStorageReflected(t *testing.T, nats nmapiv1alpha1.NATS) { + t.Helper() require.Eventually(t, func() bool { // get NATS configMap. result, err := env.GetConfigMapFromK8s(testutils.GetConfigMapName(nats), nats.Namespace) @@ -512,6 +537,7 @@ func (env TestEnvironment) EnsureNATSSpecFileStorageReflected(t *testing.T, nats // EnsureNATSSpecMemStorageReflected ensures that NATS CR Spec.jetStream.memStorage is reflected // in relevant k8s objects. func (env TestEnvironment) EnsureNATSSpecMemStorageReflected(t *testing.T, nats nmapiv1alpha1.NATS) { + t.Helper() require.Eventually(t, func() bool { // get NATS configMap. result, err := env.GetConfigMapFromK8s(testutils.GetConfigMapName(nats), nats.Namespace) @@ -533,6 +559,7 @@ func (env TestEnvironment) EnsureNATSSpecMemStorageReflected(t *testing.T, nats } func (env TestEnvironment) EnsureURLInNATSStatus(t *testing.T, name, namespace string) { + t.Helper() natsCR, err := env.GetNATSFromK8s(name, namespace) require.NoError(t, err) require.NotNil(t, natsCR)