From d1c5a736aefa2862116a668942e26bff1e31b51d Mon Sep 17 00:00:00 2001 From: James Shubin Date: Tue, 29 Oct 2019 04:12:25 -0400 Subject: [PATCH] engine: resources: Allow nil helper functions in tests This reduces some of the boilerplate when writing resource tests. --- engine/resources/resources_test.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/engine/resources/resources_test.go b/engine/resources/resources_test.go index 9cdcb2ae..21eba872 100644 --- a/engine/resources/resources_test.go +++ b/engine/resources/resources_test.go @@ -420,15 +420,20 @@ func TestResources1(t *testing.T) { }, } - t.Logf("test #%d: running startup()", index) - if err := startup(); err != nil { - t.Errorf("test #%d: FAIL", index) - t.Errorf("test #%d: could not startup: %+v", index, err) + if startup != nil { + t.Logf("test #%d: running startup()", index) + if err := startup(); err != nil { + t.Errorf("test #%d: FAIL", index) + t.Errorf("test #%d: could not startup: %+v", index, err) + } } // run init t.Logf("test #%d: running Init", index) err = res.Init(init) defer func() { + if cleanup == nil { + return + } t.Logf("test #%d: running cleanup()", index) if err := cleanup(); err != nil { 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("test #%d: running startup()", index) - if err := startup(); err != nil { - t.Errorf("test #%d: FAIL", index) - t.Errorf("test #%d: could not startup: %+v", index, err) + if startup != nil { + t.Logf("test #%d: running startup()", index) + if err := startup(); err != nil { + t.Errorf("test #%d: FAIL", index) + t.Errorf("test #%d: could not startup: %+v", index, err) + } } defer func() { + if cleanup == nil { + return + } t.Logf("test #%d: running cleanup()", index) if err := cleanup(); err != nil { t.Errorf("test #%d: FAIL", index)