From 5bca4d2313e743acfb101907a4f6e595b8c6d518 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 17 Sep 2019 13:20:38 +0300 Subject: [PATCH] io: expand panic tests to reach 100% coverage --- pkg/io/size_test.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/pkg/io/size_test.go b/pkg/io/size_test.go index d3a5ad561..dddce59ad 100644 --- a/pkg/io/size_test.go +++ b/pkg/io/size_test.go @@ -19,6 +19,15 @@ func (ss *smthSerializable) EncodeBinary(bw *BinWriter) { bw.WriteLE(ss.some) } +// Mock structure that gives error in EncodeBinary(). +type smthNotReallySerializable struct{} + +func (*smthNotReallySerializable) DecodeBinary(*BinReader) {} + +func (*smthNotReallySerializable) EncodeBinary(bw *BinWriter) { + bw.Err = fmt.Errorf("smth bad happened in smthNotReallySerializable") +} + func TestVarSize(t *testing.T) { testCases := []struct { variable interface{} @@ -179,11 +188,19 @@ func TestVarSize(t *testing.T) { } } -func TestVarSizePanic(t *testing.T) { +func panicVarSize(t *testing.T, v interface{}) { defer func() { r := recover() assert.NotNil(t, r) }() - _ = GetVarSize(t) + _ = GetVarSize(v) + // this should never execute + assert.Nil(t, t) +} + +func TestVarSizePanic(t *testing.T) { + panicVarSize(t, t) + panicVarSize(t, struct{}{}) + panicVarSize(t, &smthNotReallySerializable{}) }