Skip to content

Commit

Permalink
Add addr tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Oct 18, 2019
1 parent b7b9f11 commit 9b02e69
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions pkg/app2/appnet/addr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package appnet

import (
"net"
"testing"

"github.com/skycoin/dmsg"
"github.com/skycoin/dmsg/cipher"
"github.com/stretchr/testify/require"

"github.com/skycoin/skywire/pkg/routing"
)

func TestConvertAddr(t *testing.T) {
type want struct {
addr Addr
err error
}

pk, _ := cipher.GenerateKeyPair()
port := uint16(100)

tt := []struct {
name string
addr net.Addr
want want
}{
{
name: "ok - dmsg addr",
addr: dmsg.Addr{
PK: pk,
Port: port,
},
want: want{
addr: Addr{
Net: TypeDMSG,
PubKey: pk,
Port: routing.Port(port),
},
},
},
{
name: "ok - routing addr",
addr: routing.Addr{
PubKey: pk,
Port: routing.Port(port),
},
want: want{
addr: Addr{
Net: TypeSkynet,
PubKey: pk,
Port: routing.Port(port),
},
},
},
}

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
addr, err := ConvertAddr(tc.addr)
require.Equal(t, err, tc.want.err)
if err != nil {
return
}
require.Equal(t, addr, tc.want.addr)
})
}
}

0 comments on commit 9b02e69

Please sign in to comment.