@@ -3,9 +3,11 @@ package l402
33import (
44 "bytes"
55 "errors"
6+ "fmt"
67 "testing"
78
89 "github.com/lightningnetwork/lnd/lntypes"
10+ "github.com/stretchr/testify/require"
911)
1012
1113var (
@@ -67,3 +69,36 @@ func TestIdentifierSerialization(t *testing.T) {
6769 }
6870 }
6971}
72+
73+ // TestTokenIDString makes sure that TokenID is logged properly in Printf
74+ // function family.
75+ func TestTokenIDString (t * testing.T ) {
76+ cases := []struct {
77+ token TokenID
78+ formatString string
79+ wantText string
80+ }{
81+ {
82+ token : TokenID {1 , 2 , 3 },
83+ formatString : "client %v paid" ,
84+ wantText : "client 01020300000000000000000000000000000" +
85+ "00000000000000000000000000000 paid" ,
86+ },
87+ {
88+ token : TokenID {1 , 2 , 3 },
89+ formatString : "client %s paid" ,
90+ wantText : "client 01020300000000000000000000000000000" +
91+ "00000000000000000000000000000 paid" ,
92+ },
93+ }
94+
95+ for _ , tc := range cases {
96+ t .Run (tc .formatString , func (t * testing.T ) {
97+ got := fmt .Sprintf (tc .formatString , tc .token )
98+ require .Equal (t , tc .wantText , got )
99+
100+ got = fmt .Sprintf (tc .formatString , & tc .token )
101+ require .Equal (t , tc .wantText , got )
102+ })
103+ }
104+ }
0 commit comments