File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 11package tlv
22
33import (
4+ "testing"
5+
46 "github.com/btcsuite/btcd/btcec/v2"
57 "github.com/lightningnetwork/lnd/fn"
68 "golang.org/x/exp/constraints"
@@ -115,6 +117,29 @@ func (t *OptionalRecordT[T, V]) WhenSomeV(f func(V)) {
115117 })
116118}
117119
120+ // UnwrapOrFailV is used to extract a value from an option within a test
121+ // context. If the option is None, then the test fails. This gives the
122+ // underlying value of the record, rather then the record itself.
123+ func (o * OptionalRecordT [T , V ]) UnwrapOrFailV (t * testing.T ) V {
124+ inner := o .Option .UnwrapOrFail (t )
125+
126+ return inner .Val
127+ }
128+
129+ // UnwrapOrErr is used to extract a value from an option, if the option is
130+ // empty, then the specified error is returned directly. This gives the
131+ // underlying value of the record, instead of the record itself.
132+ func (o * OptionalRecordT [T , V ]) UnwrapOrErrV (err error ) (V , error ) {
133+ var zero V
134+
135+ inner , err := o .Option .UnwrapOrErr (err )
136+ if err != nil {
137+ return zero , err
138+ }
139+
140+ return inner .Val , nil
141+ }
142+
118143// SomeRecordT creates a new OptionalRecordT type from a given RecordT type.
119144func SomeRecordT [T TlvType , V any ](record RecordT [T , V ]) OptionalRecordT [T , V ] {
120145 return OptionalRecordT [T , V ]{
You can’t perform that action at this time.
0 commit comments