Skip to content
Snippets Groups Projects
Commit 8f6a9f78 authored by Alberto Cortés's avatar Alberto Cortés Committed by Brian Brazil
Browse files

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.
parent e0d917e2
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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)
}
}
}
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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)
}
Loading
Loading
@@ -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) {
Loading
Loading
Loading
Loading
@@ -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
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment