mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 22:37:27 -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
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/prometheus/prometheus/util/testutil"
|
||||||
|
)
|
||||||
|
|
||||||
func TestComputeExternalURL(t *testing.T) {
|
func TestComputeExternalURL(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
@ -54,13 +58,12 @@ func TestComputeExternalURL(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for _, test := range tests {
|
||||||
r, err := computeExternalURL(test.input, "0.0.0.0:9090")
|
_, err := computeExternalURL(test.input, "0.0.0.0:9090")
|
||||||
if test.valid && err != nil {
|
if test.valid {
|
||||||
t.Errorf("%d. expected input to be valid, got %s", i, err)
|
testutil.Ok(t, err)
|
||||||
} else if !test.valid && err == nil {
|
} else {
|
||||||
t.Logf("%+v", test, r)
|
testutil.NotOk(t, err)
|
||||||
t.Errorf("%d. expected input to be invalid", i)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
// Equals fails the test if exp is not equal to act.
|
||||||
func Equals(tb testing.TB, exp, act interface{}) {
|
func Equals(tb testing.TB, exp, act interface{}) {
|
||||||
if !reflect.DeepEqual(exp, act) {
|
if !reflect.DeepEqual(exp, act) {
|
||||||
|
|
Loading…
Reference in a new issue