From fec6b222d9ac46f61b0194fd343d5a10bf1e1d09 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Mon, 15 Jul 2024 13:28:14 -0400 Subject: [PATCH] Update Go tests (#1562) Add new metric that appeared in 1.22.5 and 1.21.12. * Improve test output with `cmp.Diff`. Signed-off-by: SuperQ --- prometheus/collectors/go_collector_go121_test.go | 2 ++ prometheus/collectors/go_collector_go122_test.go | 2 ++ prometheus/collectors/go_collector_latest_test.go | 15 ++++++++------- prometheus/go_collector_metrics_go121_test.go | 3 ++- prometheus/go_collector_metrics_go122_test.go | 3 ++- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/prometheus/collectors/go_collector_go121_test.go b/prometheus/collectors/go_collector_go121_test.go index 683570c..b105f71 100644 --- a/prometheus/collectors/go_collector_go121_test.go +++ b/prometheus/collectors/go_collector_go121_test.go @@ -63,6 +63,7 @@ func withAllMetrics() []string { "go_godebug_non_default_behavior_multipartmaxheaders_events_total", "go_godebug_non_default_behavior_multipartmaxparts_events_total", "go_godebug_non_default_behavior_multipathtcp_events_total", + "go_godebug_non_default_behavior_netedns0_events_total", "go_godebug_non_default_behavior_panicnil_events_total", "go_godebug_non_default_behavior_randautoseed_events_total", "go_godebug_non_default_behavior_tarinsecurepath_events_total", @@ -158,6 +159,7 @@ func withDebugMetrics() []string { "go_godebug_non_default_behavior_multipartmaxheaders_events_total", "go_godebug_non_default_behavior_multipartmaxparts_events_total", "go_godebug_non_default_behavior_multipathtcp_events_total", + "go_godebug_non_default_behavior_netedns0_events_total", "go_godebug_non_default_behavior_panicnil_events_total", "go_godebug_non_default_behavior_randautoseed_events_total", "go_godebug_non_default_behavior_tarinsecurepath_events_total", diff --git a/prometheus/collectors/go_collector_go122_test.go b/prometheus/collectors/go_collector_go122_test.go index a9cb069..0c863f1 100644 --- a/prometheus/collectors/go_collector_go122_test.go +++ b/prometheus/collectors/go_collector_go122_test.go @@ -66,6 +66,7 @@ func withAllMetrics() []string { "go_godebug_non_default_behavior_multipartmaxheaders_events_total", "go_godebug_non_default_behavior_multipartmaxparts_events_total", "go_godebug_non_default_behavior_multipathtcp_events_total", + "go_godebug_non_default_behavior_netedns0_events_total", "go_godebug_non_default_behavior_panicnil_events_total", "go_godebug_non_default_behavior_randautoseed_events_total", "go_godebug_non_default_behavior_tarinsecurepath_events_total", @@ -176,6 +177,7 @@ func withDebugMetrics() []string { "go_godebug_non_default_behavior_multipartmaxheaders_events_total", "go_godebug_non_default_behavior_multipartmaxparts_events_total", "go_godebug_non_default_behavior_multipathtcp_events_total", + "go_godebug_non_default_behavior_netedns0_events_total", "go_godebug_non_default_behavior_panicnil_events_total", "go_godebug_non_default_behavior_randautoseed_events_total", "go_godebug_non_default_behavior_tarinsecurepath_events_total", diff --git a/prometheus/collectors/go_collector_latest_test.go b/prometheus/collectors/go_collector_latest_test.go index 76673f3..c48289b 100644 --- a/prometheus/collectors/go_collector_latest_test.go +++ b/prometheus/collectors/go_collector_latest_test.go @@ -20,11 +20,12 @@ import ( "encoding/json" "log" "net/http" - "reflect" "regexp" "sort" "testing" + "github.com/google/go-cmp/cmp" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" ) @@ -69,8 +70,8 @@ func TestWithGoCollectorMemStatsMetricsDisabled(t *testing.T) { got = append(got, r.GetName()) } - if !reflect.DeepEqual(got, baseMetrics) { - t.Errorf("got %v, want %v", got, baseMetrics) + if diff := cmp.Diff(got, baseMetrics); diff != "" { + t.Errorf("missmatch (-want +got):\n%s", diff) } } @@ -127,8 +128,8 @@ func TestGoCollectorAllowList(t *testing.T) { got = append(got, r.GetName()) } - if !reflect.DeepEqual(got, test.expected) { - t.Errorf("got %v, want %v", got, test.expected) + if diff := cmp.Diff(got, test.expected); diff != "" { + t.Errorf("missmatch (-want +got):\n%s", diff) } }) } @@ -181,8 +182,8 @@ func TestGoCollectorDenyList(t *testing.T) { got = append(got, r.GetName()) } - if !reflect.DeepEqual(got, test.expected) { - t.Errorf("got %v, want %v", got, test.expected) + if diff := cmp.Diff(got, test.expected); diff != "" { + t.Errorf("missmatch (-want +got):\n%s", diff) } }) } diff --git a/prometheus/go_collector_metrics_go121_test.go b/prometheus/go_collector_metrics_go121_test.go index 90d05bd..58a8f10 100644 --- a/prometheus/go_collector_metrics_go121_test.go +++ b/prometheus/go_collector_metrics_go121_test.go @@ -52,6 +52,7 @@ var expectedRuntimeMetrics = map[string]string{ "/godebug/non-default-behavior/multipartmaxheaders:events": "go_godebug_non_default_behavior_multipartmaxheaders_events_total", "/godebug/non-default-behavior/multipartmaxparts:events": "go_godebug_non_default_behavior_multipartmaxparts_events_total", "/godebug/non-default-behavior/multipathtcp:events": "go_godebug_non_default_behavior_multipathtcp_events_total", + "/godebug/non-default-behavior/netedns0:events": "go_godebug_non_default_behavior_netedns0_events_total", "/godebug/non-default-behavior/panicnil:events": "go_godebug_non_default_behavior_panicnil_events_total", "/godebug/non-default-behavior/randautoseed:events": "go_godebug_non_default_behavior_randautoseed_events_total", "/godebug/non-default-behavior/tarinsecurepath:events": "go_godebug_non_default_behavior_tarinsecurepath_events_total", @@ -79,4 +80,4 @@ var expectedRuntimeMetrics = map[string]string{ "/sync/mutex/wait/total:seconds": "go_sync_mutex_wait_total_seconds_total", } -const expectedRuntimeMetricsCardinality = 114 +const expectedRuntimeMetricsCardinality = 115 diff --git a/prometheus/go_collector_metrics_go122_test.go b/prometheus/go_collector_metrics_go122_test.go index 86998b8..b40d93a 100644 --- a/prometheus/go_collector_metrics_go122_test.go +++ b/prometheus/go_collector_metrics_go122_test.go @@ -55,6 +55,7 @@ var expectedRuntimeMetrics = map[string]string{ "/godebug/non-default-behavior/multipartmaxheaders:events": "go_godebug_non_default_behavior_multipartmaxheaders_events_total", "/godebug/non-default-behavior/multipartmaxparts:events": "go_godebug_non_default_behavior_multipartmaxparts_events_total", "/godebug/non-default-behavior/multipathtcp:events": "go_godebug_non_default_behavior_multipathtcp_events_total", + "/godebug/non-default-behavior/netedns0:events": "go_godebug_non_default_behavior_netedns0_events_total", "/godebug/non-default-behavior/panicnil:events": "go_godebug_non_default_behavior_panicnil_events_total", "/godebug/non-default-behavior/randautoseed:events": "go_godebug_non_default_behavior_randautoseed_events_total", "/godebug/non-default-behavior/tarinsecurepath:events": "go_godebug_non_default_behavior_tarinsecurepath_events_total", @@ -90,4 +91,4 @@ var expectedRuntimeMetrics = map[string]string{ "/sync/mutex/wait/total:seconds": "go_sync_mutex_wait_total_seconds_total", } -const expectedRuntimeMetricsCardinality = 161 +const expectedRuntimeMetricsCardinality = 162