Rewrote tests for relabel and template (#3754)

* relabel: use testutil for testing

* template: use testutil for testing
This commit is contained in:
Elif T. Kuş 2018-03-29 18:02:28 +03:00 committed by Brian Brazil
parent 184b6e3767
commit daebf68ea2
2 changed files with 11 additions and 20 deletions

View File

@ -14,12 +14,12 @@
package relabel
import (
"reflect"
"testing"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/util/testutil"
)
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...)
if !reflect.DeepEqual(res, test.output) {
t.Errorf("Test %d: relabel output mismatch: expected %#v, got %#v", i+1, test.output, res)
}
testutil.Equals(t, res, test.output)
}
}

View File

@ -22,6 +22,7 @@ import (
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/util/testutil"
)
type testTemplatesScenario struct {
@ -256,7 +257,7 @@ func TestTemplateExpansion(t *testing.T) {
panic(err)
}
for i, s := range scenarios {
for _, s := range scenarios {
queryFunc := func(_ context.Context, _ string, _ time.Time) (promql.Vector, error) {
return s.queryResult, nil
}
@ -269,21 +270,14 @@ func TestTemplateExpansion(t *testing.T) {
result, err = expander.Expand()
}
if s.shouldFail {
if err == nil {
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)
}
testutil.NotOk(t, err, "%v", s.text)
continue
}
if err != nil {
t.Fatalf("%d. Error returned from %v: %v", i, s.text, err)
continue
}
if result != s.output {
t.Fatalf("%d. Error in result from %v: Expected '%v' Got '%v'", i, s.text, s.output, result)
continue
testutil.Ok(t, err)
if err == nil {
testutil.Equals(t, result, s.output)
}
}
}