@@ -74,6 +74,8 @@ func TestConstructFails(t *testing.T) {
7474 "/unix" ,
7575 "/ip4/1.2.3.4/tcp/80/unix" ,
7676 "/ip4/127.0.0.1/tcp/9090/http/p2p-webcrt-direct" ,
77+ "/" ,
78+ "" ,
7779 }
7880
7981 for _ , a := range cases {
@@ -83,6 +85,13 @@ func TestConstructFails(t *testing.T) {
8385 }
8486}
8587
88+ func TestEmptyMultiaddr (t * testing.T ) {
89+ _ , err := NewMultiaddrBytes ([]byte {})
90+ if err == nil {
91+ t .Fatal ("should have failed to parse empty multiaddr" )
92+ }
93+ }
94+
8695func TestConstructSucceeds (t * testing.T ) {
8796 cases := []string {
8897 "/ip4/1.2.3.4" ,
@@ -377,8 +386,8 @@ func TestEncapsulate(t *testing.T) {
377386
378387 m4 , _ := NewMultiaddr ("/ip4/127.0.0.1" )
379388 d := c .Decapsulate (m4 )
380- if s := d . String (); s != "" {
381- t .Error ("decapsulate /ip4 failed." , "/" , s )
389+ if d != nil {
390+ t .Error ("decapsulate /ip4 failed: " , d )
382391 }
383392}
384393
@@ -582,11 +591,11 @@ func TestBinaryMarshaler(t *testing.T) {
582591 t .Fatal (err )
583592 }
584593
585- addr2 := newMultiaddr ( t , "" )
594+ var addr2 multiaddr
586595 if err = addr2 .UnmarshalBinary (b ); err != nil {
587596 t .Fatal (err )
588597 }
589- if ! addr .Equal (addr2 ) {
598+ if ! addr .Equal (& addr2 ) {
590599 t .Error ("expected equal addresses in circular marshaling test" )
591600 }
592601}
@@ -598,11 +607,11 @@ func TestTextMarshaler(t *testing.T) {
598607 t .Fatal (err )
599608 }
600609
601- addr2 := newMultiaddr ( t , "" )
610+ var addr2 multiaddr
602611 if err = addr2 .UnmarshalText (b ); err != nil {
603612 t .Fatal (err )
604613 }
605- if ! addr .Equal (addr2 ) {
614+ if ! addr .Equal (& addr2 ) {
606615 t .Error ("expected equal addresses in circular marshaling test" )
607616 }
608617}
@@ -614,11 +623,11 @@ func TestJSONMarshaler(t *testing.T) {
614623 t .Fatal (err )
615624 }
616625
617- addr2 := newMultiaddr ( t , "" )
626+ var addr2 multiaddr
618627 if err = addr2 .UnmarshalJSON (b ); err != nil {
619628 t .Fatal (err )
620629 }
621- if ! addr .Equal (addr2 ) {
630+ if ! addr .Equal (& addr2 ) {
622631 t .Error ("expected equal addresses in circular marshaling test" )
623632 }
624633}
0 commit comments