Skip to content

Commit

Permalink
Linter: thelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiss, Tibor committed Feb 28, 2024
1 parent 91f8dff commit 2147683
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ linters:
- gomoddirectives
- testifylint
- containedctx
- thelper
- tagliatelle
- errchkjson
- perfsprint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
Expand Down
1 change: 1 addition & 0 deletions internal/controller/nats/unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type MockedUnitTestEnvironment struct {
}

func NewMockedUnitTestEnvironment(t *testing.T, objs ...client.Object) *MockedUnitTestEnvironment {
t.Helper()
// setup context
ctx := context.Background()

Expand Down
1 change: 1 addition & 0 deletions pkg/k8s/chart/helmrenderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/manager/overrides_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 27 additions & 0 deletions testutils/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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))
}

Expand All @@ -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))
}

Expand All @@ -247,45 +251,52 @@ 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
}, SmallTimeOut, SmallPollingInterval, "failed to ensure existence of ConfigMap")
}

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
}, SmallTimeOut, SmallPollingInterval, "failed to ensure existence of Secret")
}

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
}, SmallTimeOut, SmallPollingInterval, "failed to ensure existence of PodDisruptionBudget")
}

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
}, SmallTimeOut, SmallPollingInterval, "failed to ensure existence of Service")
}

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
}, SmallTimeOut, SmallPollingInterval, "failed to ensure existence of DestinationRule")
}

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 {
Expand All @@ -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 {
Expand All @@ -308,41 +320,47 @@ 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)
}, SmallTimeOut, SmallPollingInterval, "failed to ensure non-existence of ConfigMap")
}

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)
}, SmallTimeOut, SmallPollingInterval, "failed to ensure non-existence of Secret")
}

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)
}, SmallTimeOut, SmallPollingInterval, "failed to ensure non-existence of Service")
}

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)
}, SmallTimeOut, SmallPollingInterval, "failed to ensure non-existence of DestinationRule")
}

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)
}, SmallTimeOut, SmallPollingInterval, "failed to ensure non-existence of NATS")
}

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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 2147683

Please sign in to comment.