mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-13 06:47:28 -08:00
config: in tests use labels.FromStrings
Replacing code which assumes the internal structure of `Labels`. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
5421c778ba
commit
31bb281185
|
@ -74,10 +74,7 @@ var expectedConf = &Config{
|
||||||
EvaluationInterval: model.Duration(30 * time.Second),
|
EvaluationInterval: model.Duration(30 * time.Second),
|
||||||
QueryLogFile: "",
|
QueryLogFile: "",
|
||||||
|
|
||||||
ExternalLabels: labels.Labels{
|
ExternalLabels: labels.FromStrings("foo", "bar", "monitor", "codelab"),
|
||||||
{Name: "foo", Value: "bar"},
|
|
||||||
{Name: "monitor", Value: "codelab"},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
RuleFiles: []string{
|
RuleFiles: []string{
|
||||||
|
@ -1655,28 +1652,16 @@ func TestExpandExternalLabels(t *testing.T) {
|
||||||
|
|
||||||
c, err := LoadFile("testdata/external_labels.good.yml", false, false, log.NewNopLogger())
|
c, err := LoadFile("testdata/external_labels.good.yml", false, false, log.NewNopLogger())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, labels.Label{Name: "bar", Value: "foo"}, c.GlobalConfig.ExternalLabels[0])
|
require.Equal(t, labels.FromStrings("bar", "foo", "baz", "foo${TEST}bar", "foo", "${TEST}", "qux", "foo$${TEST}", "xyz", "foo$$bar"), c.GlobalConfig.ExternalLabels)
|
||||||
require.Equal(t, labels.Label{Name: "baz", Value: "foo${TEST}bar"}, c.GlobalConfig.ExternalLabels[1])
|
|
||||||
require.Equal(t, labels.Label{Name: "foo", Value: "${TEST}"}, c.GlobalConfig.ExternalLabels[2])
|
|
||||||
require.Equal(t, labels.Label{Name: "qux", Value: "foo$${TEST}"}, c.GlobalConfig.ExternalLabels[3])
|
|
||||||
require.Equal(t, labels.Label{Name: "xyz", Value: "foo$$bar"}, c.GlobalConfig.ExternalLabels[4])
|
|
||||||
|
|
||||||
c, err = LoadFile("testdata/external_labels.good.yml", false, true, log.NewNopLogger())
|
c, err = LoadFile("testdata/external_labels.good.yml", false, true, log.NewNopLogger())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, labels.Label{Name: "bar", Value: "foo"}, c.GlobalConfig.ExternalLabels[0])
|
require.Equal(t, labels.FromStrings("bar", "foo", "baz", "foobar", "foo", "", "qux", "foo${TEST}", "xyz", "foo$bar"), c.GlobalConfig.ExternalLabels)
|
||||||
require.Equal(t, labels.Label{Name: "baz", Value: "foobar"}, c.GlobalConfig.ExternalLabels[1])
|
|
||||||
require.Equal(t, labels.Label{Name: "foo", Value: ""}, c.GlobalConfig.ExternalLabels[2])
|
|
||||||
require.Equal(t, labels.Label{Name: "qux", Value: "foo${TEST}"}, c.GlobalConfig.ExternalLabels[3])
|
|
||||||
require.Equal(t, labels.Label{Name: "xyz", Value: "foo$bar"}, c.GlobalConfig.ExternalLabels[4])
|
|
||||||
|
|
||||||
os.Setenv("TEST", "TestValue")
|
os.Setenv("TEST", "TestValue")
|
||||||
c, err = LoadFile("testdata/external_labels.good.yml", false, true, log.NewNopLogger())
|
c, err = LoadFile("testdata/external_labels.good.yml", false, true, log.NewNopLogger())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, labels.Label{Name: "bar", Value: "foo"}, c.GlobalConfig.ExternalLabels[0])
|
require.Equal(t, labels.FromStrings("bar", "foo", "baz", "fooTestValuebar", "foo", "TestValue", "qux", "foo${TEST}", "xyz", "foo$bar"), c.GlobalConfig.ExternalLabels)
|
||||||
require.Equal(t, labels.Label{Name: "baz", Value: "fooTestValuebar"}, c.GlobalConfig.ExternalLabels[1])
|
|
||||||
require.Equal(t, labels.Label{Name: "foo", Value: "TestValue"}, c.GlobalConfig.ExternalLabels[2])
|
|
||||||
require.Equal(t, labels.Label{Name: "qux", Value: "foo${TEST}"}, c.GlobalConfig.ExternalLabels[3])
|
|
||||||
require.Equal(t, labels.Label{Name: "xyz", Value: "foo$bar"}, c.GlobalConfig.ExternalLabels[4])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyGlobalBlock(t *testing.T) {
|
func TestEmptyGlobalBlock(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue