From: Daniel Swarbrick <dswarbrick@debian.org>
Date: Thu, 20 Feb 2025 01:51:32 +0100
Subject: Default to legacy label name validation in tests

Forwarded: not-needed
Last-Update: 2025-02-20

Restore pre-v0.62.0 prometheus/common default label name validation.
This patch can (and should) be dropped once Alertmanager is updated to
natively support prometheus/common v0.62.0+.
---
 config/config_test.go        | 5 +++++
 matcher/compat/parse_test.go | 5 +++++
 silence/silence_test.go      | 5 +++++
 3 files changed, 15 insertions(+)

diff --git a/config/config_test.go b/config/config_test.go
index 728d767..082d432 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -33,6 +33,11 @@ import (
 	"github.com/prometheus/alertmanager/matcher/compat"
 )
 
+func TestMain(m *testing.M) {
+	model.NameValidationScheme = model.LegacyValidation
+	m.Run()
+}
+
 func TestLoadEmptyString(t *testing.T) {
 	var in string
 	_, err := Load(in)
diff --git a/matcher/compat/parse_test.go b/matcher/compat/parse_test.go
index 803ee78..4d8ecbb 100644
--- a/matcher/compat/parse_test.go
+++ b/matcher/compat/parse_test.go
@@ -23,6 +23,11 @@ import (
 	"github.com/prometheus/alertmanager/pkg/labels"
 )
 
+func TestMain(m *testing.M) {
+	model.NameValidationScheme = model.LegacyValidation
+	m.Run()
+}
+
 func TestFallbackMatcherParser(t *testing.T) {
 	tests := []struct {
 		name     string
diff --git a/silence/silence_test.go b/silence/silence_test.go
index a65b1f6..e007aff 100644
--- a/silence/silence_test.go
+++ b/silence/silence_test.go
@@ -39,6 +39,11 @@ import (
 	"github.com/prometheus/alertmanager/types"
 )
 
+func TestMain(m *testing.M) {
+	model.NameValidationScheme = model.LegacyValidation
+	m.Run()
+}
+
 func checkErr(t *testing.T, expected string, got error) {
 	t.Helper()
 
