mirror of
https://github.com/prometheus/prometheus
synced 2024-12-25 16:02:28 +00:00
config: simplify tests by using testutil.NotOk (#3289)
Also include filename in all LoadFile errors Also add mesage to testuitl.NotOk so we can identify failing tests when using table driven tests.
This commit is contained in:
parent
e0d917e2f5
commit
8f6a9f7833
@ -63,7 +63,7 @@ func TestComputeExternalURL(t *testing.T) {
|
||||
if test.valid {
|
||||
testutil.Ok(t, err)
|
||||
} else {
|
||||
testutil.NotOk(t, err)
|
||||
testutil.NotOk(t, err, "input=%q: ", test.input)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func LoadFile(filename string) (*Config, error) {
|
||||
}
|
||||
cfg, err := Load(string(content))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("parsing YAML file %s: %v", filename, err)
|
||||
}
|
||||
resolveFilepaths(filepath.Dir(filename), cfg)
|
||||
return cfg, nil
|
||||
|
@ -673,8 +673,7 @@ var expectedErrors = []struct {
|
||||
func TestBadConfigs(t *testing.T) {
|
||||
for _, ee := range expectedErrors {
|
||||
_, err := LoadFile("testdata/" + ee.filename)
|
||||
testutil.Assert(t, err != nil,
|
||||
"Expected error parsing %s but got none", ee.filename)
|
||||
testutil.NotOk(t, err, "%s: ", ee.filename)
|
||||
testutil.Assert(t, strings.Contains(err.Error(), ee.errMsg),
|
||||
"Expected error for %s to contain %q but got: %s", ee.filename, ee.errMsg, err)
|
||||
}
|
||||
@ -685,7 +684,7 @@ func TestBadStaticConfigs(t *testing.T) {
|
||||
testutil.Ok(t, err)
|
||||
var tg TargetGroup
|
||||
err = json.Unmarshal(content, &tg)
|
||||
testutil.Assert(t, err != nil, "Expected unmarshal error but got none.")
|
||||
testutil.NotOk(t, err, "", nil)
|
||||
}
|
||||
|
||||
func TestEmptyConfig(t *testing.T) {
|
||||
|
@ -49,10 +49,10 @@ func Ok(tb testing.TB, err error) {
|
||||
}
|
||||
|
||||
// NotOk fails the test if an err is nil.
|
||||
func NotOk(tb testing.TB, err error) {
|
||||
func NotOk(tb testing.TB, err error, msg string, v ...interface{}) {
|
||||
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)
|
||||
fmt.Printf("\033[31m%s:%d: "+msg+"expected error, got nothing\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...)
|
||||
tb.FailNow()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user