From dd24152e78fa01c79f5830d59e11d825c120b60e Mon Sep 17 00:00:00 2001 From: Catenocrypt Date: Tue, 27 Oct 2020 20:51:23 +0100 Subject: [PATCH] Test runner tweak, for coverage. --- test_runner.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test_runner.go b/test_runner.go index 6fe2dbf..9eadebd 100644 --- a/test_runner.go +++ b/test_runner.go @@ -33,15 +33,19 @@ func RunTestsEncode(t *testing.T, coinType uint32, tests []TestcaseEncode) { } } +func errorString(err error) string { + if err != nil { + return err.Error() + } + return "(no error)" +} + func RunTestEncode(coinType uint32, tt TestcaseEncode) error { testfun, _ := toBytesMap[coinType] got, err := testfun(tt.input) - var goterror string = "(no error)" - if err != nil { - goterror = err.Error() - } + goterror := errorString(err) if tt.err != nil { if !strings.HasPrefix(goterror, tt.err.Error()) { return fmt.Errorf("%v %v: ToBytes() error = %v, wantErr %v", coinType, tt.name, goterror, tt.err) @@ -75,10 +79,7 @@ func RunTestDecode(coinType uint32, tt TestcaseDecode) error { got, err := testfun(decoded) - var goterror string = "(no error)" - if err != nil { - goterror = err.Error() - } + goterror := errorString(err) if tt.err != nil { if goterror != tt.err.Error() { return fmt.Errorf("%v %v: ToString() error = %v, wantErr %v", coinType, tt.name, goterror, tt.err)