mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
adding unit test for target group (#6138)
Signed-off-by: Jean-Baptiste Le Duigou <jb.leduigou@gmail.com>
This commit is contained in:
parent
b05b5f9a30
commit
5146bb14ef
|
@ -18,6 +18,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/util/testutil"
|
"github.com/prometheus/prometheus/util/testutil"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTargetGroupStrictJsonUnmarshal(t *testing.T) {
|
func TestTargetGroupStrictJsonUnmarshal(t *testing.T) {
|
||||||
|
@ -46,3 +47,45 @@ func TestTargetGroupStrictJsonUnmarshal(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTargetGroupYamlUnmarshal(t *testing.T) {
|
||||||
|
unmarshal := func(d []byte) func(interface{}) error {
|
||||||
|
return func(o interface{}) error {
|
||||||
|
return yaml.Unmarshal(d, o)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
yaml string
|
||||||
|
expectedNumberOfTargets int
|
||||||
|
expectedNumberOfLabels int
|
||||||
|
expectedReply error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
yaml: "labels:\ntargets:\n",
|
||||||
|
expectedNumberOfTargets: 0,
|
||||||
|
expectedNumberOfLabels: 0,
|
||||||
|
expectedReply: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
yaml: "labels:\n my: label\ntargets:\n ['localhost:9090', 'localhost:9191']",
|
||||||
|
expectedNumberOfTargets: 2,
|
||||||
|
expectedNumberOfLabels: 1,
|
||||||
|
expectedReply: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
yaml: "labels:\ntargets:\n 'localhost:9090'",
|
||||||
|
expectedNumberOfTargets: 0,
|
||||||
|
expectedNumberOfLabels: 0,
|
||||||
|
expectedReply: &yaml.TypeError{Errors: []string{"line 3: cannot unmarshal !!str `localho...` into []string"}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
tg := Group{}
|
||||||
|
actual := tg.UnmarshalYAML(unmarshal([]byte(test.yaml)))
|
||||||
|
testutil.Equals(t, test.expectedReply, actual)
|
||||||
|
testutil.Equals(t, test.expectedNumberOfTargets, len(tg.Targets))
|
||||||
|
testutil.Equals(t, test.expectedNumberOfLabels, len(tg.Labels))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue