mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
Merge pull request #3285 from jlevesy/use-testutils-in-cmd-subpackage
Use testutil assertion helpers in cmd package
This commit is contained in:
commit
3589f2f1d4
|
@ -13,7 +13,11 @@
|
|||
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prometheus/prometheus/util/testutil"
|
||||
)
|
||||
|
||||
func TestComputeExternalURL(t *testing.T) {
|
||||
tests := []struct {
|
||||
|
@ -54,13 +58,12 @@ func TestComputeExternalURL(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
r, err := computeExternalURL(test.input, "0.0.0.0:9090")
|
||||
if test.valid && err != nil {
|
||||
t.Errorf("%d. expected input to be valid, got %s", i, err)
|
||||
} else if !test.valid && err == nil {
|
||||
t.Logf("%+v", test, r)
|
||||
t.Errorf("%d. expected input to be invalid", i)
|
||||
for _, test := range tests {
|
||||
_, err := computeExternalURL(test.input, "0.0.0.0:9090")
|
||||
if test.valid {
|
||||
testutil.Ok(t, err)
|
||||
} else {
|
||||
testutil.NotOk(t, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,15 @@ func Ok(tb testing.TB, err error) {
|
|||
}
|
||||
}
|
||||
|
||||
// NotOk fails the test if an err is nil.
|
||||
func NotOk(tb testing.TB, err error) {
|
||||
if err == nil {
|
||||
_, file, line, _ := runtime.Caller(1)
|
||||
fmt.Printf("\033[31m%s:%d: expected error, got nothing \033[39m\n\n", filepath.Base(file), line)
|
||||
tb.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
// Equals fails the test if exp is not equal to act.
|
||||
func Equals(tb testing.TB, exp, act interface{}) {
|
||||
if !reflect.DeepEqual(exp, act) {
|
||||
|
|
Loading…
Reference in a new issue