mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-11 13:57:36 -08:00
Rewrote tests for relabel and template (#3754)
* relabel: use testutil for testing * template: use testutil for testing
This commit is contained in:
parent
184b6e3767
commit
daebf68ea2
|
@ -14,12 +14,12 @@
|
||||||
package relabel
|
package relabel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/config"
|
"github.com/prometheus/prometheus/config"
|
||||||
|
"github.com/prometheus/prometheus/util/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRelabel(t *testing.T) {
|
func TestRelabel(t *testing.T) {
|
||||||
|
@ -412,11 +412,8 @@ func TestRelabel(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for _, test := range tests {
|
||||||
res := Process(test.input, test.relabel...)
|
res := Process(test.input, test.relabel...)
|
||||||
|
testutil.Equals(t, res, test.output)
|
||||||
if !reflect.DeepEqual(res, test.output) {
|
|
||||||
t.Errorf("Test %d: relabel output mismatch: expected %#v, got %#v", i+1, test.output, res)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/pkg/labels"
|
"github.com/prometheus/prometheus/pkg/labels"
|
||||||
"github.com/prometheus/prometheus/promql"
|
"github.com/prometheus/prometheus/promql"
|
||||||
|
"github.com/prometheus/prometheus/util/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testTemplatesScenario struct {
|
type testTemplatesScenario struct {
|
||||||
|
@ -256,7 +257,7 @@ func TestTemplateExpansion(t *testing.T) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
queryFunc := func(_ context.Context, _ string, _ time.Time) (promql.Vector, error) {
|
queryFunc := func(_ context.Context, _ string, _ time.Time) (promql.Vector, error) {
|
||||||
return s.queryResult, nil
|
return s.queryResult, nil
|
||||||
}
|
}
|
||||||
|
@ -269,21 +270,14 @@ func TestTemplateExpansion(t *testing.T) {
|
||||||
result, err = expander.Expand()
|
result, err = expander.Expand()
|
||||||
}
|
}
|
||||||
if s.shouldFail {
|
if s.shouldFail {
|
||||||
if err == nil {
|
testutil.NotOk(t, err, "%v", s.text)
|
||||||
t.Fatalf("%d. Error not returned from %v", i, s.text)
|
|
||||||
}
|
|
||||||
if err.Error() != s.errorMsg {
|
|
||||||
t.Fatalf("%d. Error message returned is wrong:\n returned: %v\n expected: %v", i, err.Error(), s.errorMsg)
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("%d. Error returned from %v: %v", i, s.text, err)
|
testutil.Ok(t, err)
|
||||||
continue
|
|
||||||
}
|
if err == nil {
|
||||||
if result != s.output {
|
testutil.Equals(t, result, s.output)
|
||||||
t.Fatalf("%d. Error in result from %v: Expected '%v' Got '%v'", i, s.text, s.output, result)
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue