Skip to content

Commit

Permalink
test: Provide better error messages in assertions (#1266)
Browse files Browse the repository at this point in the history
  • Loading branch information
k15r authored Jul 17, 2024
1 parent 4e2a7b9 commit 161b8cc
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 81 deletions.
26 changes: 13 additions & 13 deletions test/e2e/logs_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,79 +108,79 @@ var _ = Describe(suite.ID(), Label(suite.LabelLogs), Ordered, func() {
var serviceAccount corev1.ServiceAccount
err := k8sClient.Get(ctx, kitkyma.FluentBitServiceAccount, &serviceAccount)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "ServiceAccount still exists")

Eventually(func(g Gomega) bool {
var clusterRole rbacv1.ClusterRole
err := k8sClient.Get(ctx, kitkyma.FluentBitClusterRole, &clusterRole)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "ClusterRole still exists")

Eventually(func(g Gomega) bool {
var clusterRoleBinding rbacv1.ClusterRoleBinding
err := k8sClient.Get(ctx, kitkyma.FluentBitClusterRoleBinding, &clusterRoleBinding)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "ClusterRoleBinding still exists")

Eventually(func(g Gomega) bool {
var service corev1.Service
err := k8sClient.Get(ctx, kitkyma.FluentBitExporterMetricsService, &service)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "Exporter metrics service still exists")

Eventually(func(g Gomega) bool {
var service corev1.Service
err := k8sClient.Get(ctx, kitkyma.FluentBitMetricsService, &service)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "Metrics service still exists")

Eventually(func(g Gomega) bool {
var networkPolicy networkingv1.NetworkPolicy
err := k8sClient.Get(ctx, kitkyma.FluentBitNetworkPolicy, &networkPolicy)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "Network policy still exists")

Eventually(func(g Gomega) bool {
var configMap corev1.ConfigMap
err := k8sClient.Get(ctx, kitkyma.FluentBitConfigMap, &configMap)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "ConfigMap still exists")

Eventually(func(g Gomega) bool {
var configMap corev1.ConfigMap
err := k8sClient.Get(ctx, kitkyma.FluentBitLuaConfigMap, &configMap)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "Lua ConfigMap still exists")

Eventually(func(g Gomega) bool {
var configMap corev1.ConfigMap
err := k8sClient.Get(ctx, kitkyma.FluentBitParserConfigMap, &configMap)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "Parser ConfigMap still exists")

Eventually(func(g Gomega) bool {
var configMap corev1.ConfigMap
err := k8sClient.Get(ctx, kitkyma.FluentBitSectionsConfigMap, &configMap)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "Sections ConfigMap still exists")

Eventually(func(g Gomega) bool {
var configMap corev1.ConfigMap
err := k8sClient.Get(ctx, kitkyma.FluentBitFilesConfigMap, &configMap)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "Files ConfigMap still exists")

Eventually(func(g Gomega) bool {
var daemonSet appsv1.DaemonSet
err := k8sClient.Get(ctx, kitkyma.FluentBitDaemonSet, &daemonSet)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "DaemonSet still exists")

Eventually(func(g Gomega) bool {
var service corev1.Service
err := k8sClient.Get(ctx, kitkyma.TraceGatewayOTLPService, &service)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "OTLP service still exists")
})
})
})
2 changes: 1 addition & 1 deletion test/e2e/logs_self_monitor_healthy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var _ = Describe(suite.ID(), Label(suite.LabelSelfMonitoringLogsHealthy), Ordere
var pipeline telemetryv1alpha1.LogPipeline
key := types.NamespacedName{Name: pipelineName}
g.Expect(k8sClient.Get(ctx, key, &pipeline)).To(Succeed())
g.Expect(meta.IsStatusConditionTrue(pipeline.Status.Conditions, conditions.TypeFlowHealthy)).To(BeTrue())
g.Expect(meta.IsStatusConditionTrue(pipeline.Status.Conditions, conditions.TypeFlowHealthy)).To(BeTrueBecause("Flow not healthy"))
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed())
})

Expand Down
32 changes: 16 additions & 16 deletions test/e2e/metrics_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,97 +143,97 @@ func gatewayResourcesAreDeleted() {
var serviceAccount corev1.ServiceAccount
err := k8sClient.Get(ctx, kitkyma.MetricGatewayServiceAccount, &serviceAccount)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "ServiceAccount still exists")

Eventually(func(g Gomega) bool {
var clusterRole rbacv1.ClusterRole
err := k8sClient.Get(ctx, kitkyma.MetricGatewayClusterRole, &clusterRole)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "ClusterRole still exists")

Eventually(func(g Gomega) bool {
var clusterRoleBinding rbacv1.ClusterRoleBinding
err := k8sClient.Get(ctx, kitkyma.MetricGatewayClusterRoleBinding, &clusterRoleBinding)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "ClusterRoleBinding still exists")

Eventually(func(g Gomega) bool {
var service corev1.Service
err := k8sClient.Get(ctx, kitkyma.MetricGatewayMetricsService, &service)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "Service still exists")

Eventually(func(g Gomega) bool {
var networkPolicy networkingv1.NetworkPolicy
err := k8sClient.Get(ctx, kitkyma.MetricGatewayNetworkPolicy, &networkPolicy)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "NetworkPolicy still exists")

Eventually(func(g Gomega) bool {
var secret corev1.Secret
err := k8sClient.Get(ctx, kitkyma.MetricGatewaySecretName, &secret)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "Secret still exists")

Eventually(func(g Gomega) bool {
var configMap corev1.ConfigMap
err := k8sClient.Get(ctx, kitkyma.MetricGatewayConfigMap, &configMap)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "ConfigMap still exists")

Eventually(func(g Gomega) bool {
var service corev1.Service
err := k8sClient.Get(ctx, kitkyma.MetricGatewayOTLPService, &service)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "OTLP Service still exists")

Eventually(func(g Gomega) bool {
var deployment appsv1.Deployment
err := k8sClient.Get(ctx, kitkyma.MetricGatewayName, &deployment)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "Deployment still exists")
}

func agentResourcesAreDeleted() {
Eventually(func(g Gomega) bool {
var serviceAccount corev1.ServiceAccount
err := k8sClient.Get(ctx, kitkyma.MetricAgentServiceAccount, &serviceAccount)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "ServiceAccount still exists")

Eventually(func(g Gomega) bool {
var clusterRole rbacv1.ClusterRole
err := k8sClient.Get(ctx, kitkyma.MetricAgentClusterRole, &clusterRole)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "ClusterRole still exists")

Eventually(func(g Gomega) bool {
var clusterRoleBinding rbacv1.ClusterRoleBinding
err := k8sClient.Get(ctx, kitkyma.MetricAgentClusterRoleBinding, &clusterRoleBinding)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "ClusterRoleBinding still exists")

Eventually(func(g Gomega) bool {
var service corev1.Service
err := k8sClient.Get(ctx, kitkyma.MetricAgentMetricsService, &service)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "Service still exists")

Eventually(func(g Gomega) bool {
var networkPolicy networkingv1.NetworkPolicy
err := k8sClient.Get(ctx, kitkyma.MetricAgentNetworkPolicy, &networkPolicy)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "NetworkPolicy still exists")

Eventually(func(g Gomega) bool {
var configMap corev1.ConfigMap
err := k8sClient.Get(ctx, kitkyma.MetricAgentConfigMap, &configMap)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "ConfigMap still exists")

Eventually(func(g Gomega) bool {
var daemonSet appsv1.DaemonSet
err := k8sClient.Get(ctx, kitkyma.MetricAgentName, &daemonSet)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "DaemonSet still exists")
}
2 changes: 1 addition & 1 deletion test/e2e/metrics_secret_rotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var _ = Describe(suite.ID(), Label(suite.LabelMetrics), Ordered, func() {
var deployment appsv1.Deployment
err := k8sClient.Get(ctx, kitkyma.MetricGatewayName, &deployment)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "Deployment still exists")
})

It("Should have running metricpipeline", func() {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/metrics_self_monitor_healthy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var _ = Describe(suite.ID(), Label(suite.LabelSelfMonitoringMetricsHealthy), Ord
var pipeline telemetryv1alpha1.MetricPipeline
key := types.NamespacedName{Name: pipelineName}
g.Expect(k8sClient.Get(ctx, key, &pipeline)).To(Succeed())
g.Expect(meta.IsStatusConditionTrue(pipeline.Status.Conditions, conditions.TypeFlowHealthy)).To(BeTrue())
g.Expect(meta.IsStatusConditionTrue(pipeline.Status.Conditions, conditions.TypeFlowHealthy)).To(BeTrueBecause("Flow not healthy"))
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(Succeed())
})

Expand Down
3 changes: 2 additions & 1 deletion test/e2e/metrics_service_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package e2e

import (
"fmt"
"net/http"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -85,7 +86,7 @@ var _ = Describe(suite.ID(), Label(suite.LabelMetrics), Ordered, func() {
ContainResourceAttrs(HaveKeyWithValue("k8s.pod.name", ContainSubstring(givenPodPrefix))),
)),
))
}, periodic.TelemetryEventuallyTimeout, periodic.TelemetryInterval).Should(Succeed())
}, periodic.TelemetryEventuallyTimeout, periodic.TelemetryInterval).Should(Succeed(), fmt.Sprintf("could not find metrics matching service.name: %s, k8s.pod.name: %s.*", expectedServiceName, givenPodPrefix))
}

It("Should set undefined service.name attribute to app.kubernetes.io/name label value", func() {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (

func TestE2E(t *testing.T) {
format.MaxDepth = 20
format.MaxLength = 16000
format.MaxLength = 0
RegisterFailHandler(Fail)
RunSpecs(t, "E2E Suite")
}
Expand Down
15 changes: 7 additions & 8 deletions test/e2e/telemetry_logs_analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,32 @@ var _ = Describe(suite.ID(), Label(suite.LabelTelemetryLogAnalysis), Ordered, fu
makeResourcesTracePipeline := func(backendName string) []client.Object {
var objs []client.Object

//backend
// backend
traceBackend := backend.New(namespace, backend.SignalTypeTraces, backend.WithName(backendName))
traceBackendURL = traceBackend.ExportURL(proxyClient)
objs = append(objs, traceBackend.K8sObjects()...)

//pipeline
// pipeline
tracePipeline := testutils.NewTracePipelineBuilder().
WithName(backendName).
WithOTLPOutput(testutils.OTLPEndpoint(traceBackend.Endpoint())).
Build()
objs = append(objs, &tracePipeline)

//client
// client
objs = append(objs, kitk8s.NewPod("telemetrygen-traces", namespace).WithPodSpec(telemetrygen.PodSpec(telemetrygen.SignalTypeTraces)).K8sObject())
return objs
}

makeResourcesMetricPipeline := func(backendName string) []client.Object {
var objs []client.Object

//backend
// backend
metricBackend := backend.New(namespace, backend.SignalTypeMetrics, backend.WithName(backendName))
metricBackendURL = metricBackend.ExportURL(proxyClient)
objs = append(objs, metricBackend.K8sObjects()...)

//pipeline
// pipeline
metricPipeline := testutils.NewMetricPipelineBuilder().
WithName(backendName).
WithPrometheusInput(true, testutils.IncludeNamespaces(namespace)).
Expand All @@ -85,7 +85,7 @@ var _ = Describe(suite.ID(), Label(suite.LabelTelemetryLogAnalysis), Ordered, fu
Build()
objs = append(objs, &metricPipeline)

//client
// client
objs = append(objs, trafficgen.K8sObjects(namespace)...)
objs = append(objs, kitk8s.NewPod("telemetrygen-metrics", namespace).WithPodSpec(telemetrygen.PodSpec(telemetrygen.SignalTypeMetrics)).K8sObject())

Expand All @@ -107,7 +107,7 @@ var _ = Describe(suite.ID(), Label(suite.LabelTelemetryLogAnalysis), Ordered, fu
Build()
objs = append(objs, &logPipeline)

//no client
// no client
return objs
}

Expand All @@ -132,7 +132,6 @@ var _ = Describe(suite.ID(), Label(suite.LabelTelemetryLogAnalysis), Ordered, fu

Context("When all components are deployed", func() {
BeforeAll(func() {
format.MaxLength = 0 // remove Gomega truncation
var k8sObjects []client.Object
k8sObjects = append(k8sObjects, kitk8s.NewNamespace(namespace).K8sObject())
k8sObjects = append(k8sObjects, makeResourcesTracePipeline(traceBackendName)...)
Expand Down
28 changes: 14 additions & 14 deletions test/e2e/traces_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,59 +92,59 @@ var _ = Describe(suite.ID(), Label(suite.LabelTraces), func() {
Expect(k8sClient.Delete(ctx, secret.K8sObject())).Should(Succeed())
})

Eventually(func(g Gomega) bool {
var clusterRoleBinding rbacv1.ClusterRoleBinding
err := k8sClient.Get(ctx, kitkyma.TraceGatewayClusterRoleBinding, &clusterRoleBinding)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "ClusterRoleBinding still exists")

Eventually(func(g Gomega) bool {
var serviceAccount corev1.ServiceAccount
err := k8sClient.Get(ctx, kitkyma.TraceGatewayServiceAccount, &serviceAccount)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "ServiceAccount still exists")

Eventually(func(g Gomega) bool {
var clusterRole rbacv1.ClusterRole
err := k8sClient.Get(ctx, kitkyma.TraceGatewayClusterRole, &clusterRole)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())

Eventually(func(g Gomega) bool {
var clusterRoleBinding rbacv1.ClusterRoleBinding
err := k8sClient.Get(ctx, kitkyma.TraceGatewayClusterRoleBinding, &clusterRoleBinding)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "ClusterRole still exists")

Eventually(func(g Gomega) bool {
var service corev1.Service
err := k8sClient.Get(ctx, kitkyma.TraceGatewayMetricsService, &service)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "Metrics service still exists")

Eventually(func(g Gomega) bool {
var networkPolicy networkingv1.NetworkPolicy
err := k8sClient.Get(ctx, kitkyma.TraceGatewayNetworkPolicy, &networkPolicy)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "NetworkPolicy still exists")

Eventually(func(g Gomega) bool {
var secret corev1.Secret
err := k8sClient.Get(ctx, kitkyma.TraceGatewaySecretName, &secret)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "TraceGatewaySecret still exists")

Eventually(func(g Gomega) bool {
var configMap corev1.ConfigMap
err := k8sClient.Get(ctx, kitkyma.TraceGatewayConfigMap, &configMap)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "TraceGatewayConfigMap still exists")

Eventually(func(g Gomega) bool {
var deployment appsv1.Deployment
err := k8sClient.Get(ctx, kitkyma.TraceGatewayName, &deployment)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "Deployment still exists")

Eventually(func(g Gomega) bool {
var service corev1.Service
err := k8sClient.Get(ctx, kitkyma.TraceGatewayOTLPService, &service)
return apierrors.IsNotFound(err)
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue())
}, periodic.EventuallyTimeout, periodic.DefaultInterval).Should(BeTrue(), "OTLP service still exists")
})
})
})
Loading

0 comments on commit 161b8cc

Please sign in to comment.