@@ -25,8 +25,12 @@ import (
2525
2626 commoncfg "github.com/prometheus/common/config"
2727 "github.com/prometheus/common/model"
28+ "github.com/prometheus/common/promslog"
2829 "github.com/stretchr/testify/require"
2930 "gopkg.in/yaml.v2"
31+
32+ "github.com/prometheus/alertmanager/featurecontrol"
33+ "github.com/prometheus/alertmanager/matcher/compat"
3034)
3135
3236func TestLoadEmptyString (t * testing.T ) {
@@ -1387,3 +1391,45 @@ func TestNilRegexp(t *testing.T) {
13871391 })
13881392 }
13891393}
1394+
1395+ func TestInhibitRuleEqual (t * testing.T ) {
1396+ c , err := LoadFile ("testdata/conf.inhibit-equal.yml" )
1397+ require .NoError (t , err )
1398+
1399+ // The inhibition rule should have the expected equal labels.
1400+ require .Len (t , c .InhibitRules , 1 )
1401+ r := c .InhibitRules [0 ]
1402+ require .Equal (t , model.LabelNames {"qux" , "corge" }, r .Equal )
1403+
1404+ // Should not be able to load configuration with UTF-8 in equals list.
1405+ _ , err = LoadFile ("testdata/conf.inhibit-equal-utf8.yml" )
1406+ require .Error (t , err )
1407+ require .Equal (t , "invalid label name \" qux🙂\" in equal list" , err .Error ())
1408+
1409+ // Change the mode to UTF-8 mode.
1410+ ff , err := featurecontrol .NewFlags (promslog .NewNopLogger (), featurecontrol .FeatureUTF8StrictMode )
1411+ require .NoError (t , err )
1412+ compat .InitFromFlags (promslog .NewNopLogger (), ff )
1413+
1414+ // Restore the mode to classic at the end of the test.
1415+ ff , err = featurecontrol .NewFlags (promslog .NewNopLogger (), featurecontrol .FeatureClassicMode )
1416+ require .NoError (t , err )
1417+ defer compat .InitFromFlags (promslog .NewNopLogger (), ff )
1418+
1419+ c , err = LoadFile ("testdata/conf.inhibit-equal.yml" )
1420+ require .NoError (t , err )
1421+
1422+ // The inhibition rule should have the expected equal labels.
1423+ require .Len (t , c .InhibitRules , 1 )
1424+ r = c .InhibitRules [0 ]
1425+ require .Equal (t , model.LabelNames {"qux" , "corge" }, r .Equal )
1426+
1427+ // Should also be able to load configuration with UTF-8 in equals list.
1428+ c , err = LoadFile ("testdata/conf.inhibit-equal-utf8.yml" )
1429+ require .NoError (t , err )
1430+
1431+ // The inhibition rule should have the expected equal labels.
1432+ require .Len (t , c .InhibitRules , 1 )
1433+ r = c .InhibitRules [0 ]
1434+ require .Equal (t , model.LabelNames {"qux🙂" , "corge" }, r .Equal )
1435+ }
0 commit comments