From 681f44fd16d6b045d87a25a17e950d3030d6962f Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 29 Aug 2024 20:51:09 -0500 Subject: [PATCH] lnwire: modify TestLightningWireProtocol to use sub-tests This way, it's possible to run induvidual tests to target failures. --- lnwire/lnwire_test.go | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index c9413d4c2..f326cf10a 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -887,7 +887,7 @@ func TestLightningWireProtocol(t *testing.T) { v[0] = reflect.ValueOf(ks) }, MsgCommitSig: func(v []reflect.Value, r *rand.Rand) { - req := NewCommitSig() + req := &CommitSig{} if _, err := r.Read(req.ChanID[:]); err != nil { t.Fatalf("unable to generate chan id: %v", err) return @@ -1653,22 +1653,28 @@ func TestLightningWireProtocol(t *testing.T) { }, } for _, test := range tests { - var config *quick.Config + t.Run(test.msgType.String(), func(t *testing.T) { + var config *quick.Config - // If the type defined is within the custom type gen map above, - // then we'll modify the default config to use this Value - // function that knows how to generate the proper types. - if valueGen, ok := customTypeGen[test.msgType]; ok { - config = &quick.Config{ - Values: valueGen, + // If the type defined is within the custom type gen + // map above, then we'll modify the default config to + // use this Value function that knows how to generate + // the proper types. + if valueGen, ok := customTypeGen[test.msgType]; ok { + config = &quick.Config{ + Values: valueGen, + } } - } - t.Logf("Running fuzz tests for msgType=%v", test.msgType) - if err := quick.Check(test.scenario, config); err != nil { - t.Fatalf("fuzz checks for msg=%v failed: %v", - test.msgType, err) - } + t.Logf("Running fuzz tests for msgType=%v", + test.msgType) + + err := quick.Check(test.scenario, config) + if err != nil { + t.Fatalf("fuzz checks for msg=%v failed: %v", + test.msgType, err) + } + }) } }