engine: resources: Allow nil helper functions in tests

This reduces some of the boilerplate when writing resource tests.
This commit is contained in:
James Shubin
2019-10-29 04:12:25 -04:00
parent 6b1e038c5c
commit d1c5a736ae

View File

@@ -420,15 +420,20 @@ func TestResources1(t *testing.T) {
}, },
} }
t.Logf("test #%d: running startup()", index) if startup != nil {
if err := startup(); err != nil { t.Logf("test #%d: running startup()", index)
t.Errorf("test #%d: FAIL", index) if err := startup(); err != nil {
t.Errorf("test #%d: could not startup: %+v", index, err) t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: could not startup: %+v", index, err)
}
} }
// run init // run init
t.Logf("test #%d: running Init", index) t.Logf("test #%d: running Init", index)
err = res.Init(init) err = res.Init(init)
defer func() { defer func() {
if cleanup == nil {
return
}
t.Logf("test #%d: running cleanup()", index) t.Logf("test #%d: running cleanup()", index)
if err := cleanup(); err != nil { if err := cleanup(); err != nil {
t.Errorf("test #%d: FAIL", index) t.Errorf("test #%d: FAIL", index)
@@ -1247,12 +1252,17 @@ func TestResources2(t *testing.T) {
// t.Logf(fmt.Sprintf("test #%d: ", index)+format, v...) // t.Logf(fmt.Sprintf("test #%d: ", index)+format, v...)
//} //}
t.Logf("test #%d: running startup()", index) if startup != nil {
if err := startup(); err != nil { t.Logf("test #%d: running startup()", index)
t.Errorf("test #%d: FAIL", index) if err := startup(); err != nil {
t.Errorf("test #%d: could not startup: %+v", index, err) t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: could not startup: %+v", index, err)
}
} }
defer func() { defer func() {
if cleanup == nil {
return
}
t.Logf("test #%d: running cleanup()", index) t.Logf("test #%d: running cleanup()", index)
if err := cleanup(); err != nil { if err := cleanup(); err != nil {
t.Errorf("test #%d: FAIL", index) t.Errorf("test #%d: FAIL", index)