diff --git a/cmd/prometheus/main_test.go b/cmd/prometheus/main_test.go index e327b9014..055db7158 100644 --- a/cmd/prometheus/main_test.go +++ b/cmd/prometheus/main_test.go @@ -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) } } } diff --git a/config/config.go b/config/config.go index 0e9eadb69..ab4208008 100644 --- a/config/config.go +++ b/config/config.go @@ -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 diff --git a/config/config_test.go b/config/config_test.go index f99e85f35..557c28dde 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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) { diff --git a/util/testutil/testing.go b/util/testutil/testing.go index cde0e4f91..5cd4a5bae 100644 --- a/util/testutil/testing.go +++ b/util/testutil/testing.go @@ -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() } }