mirror of
https://github.com/h44z/wg-portal.git
synced 2026-05-28 08:56:17 +00:00
Fix single-peer interface import mode (#695)
Co-authored-by: nbk1982 <16351736+nbk1982@users.noreply.github.com>
This commit is contained in:
@@ -10,6 +10,49 @@ import (
|
||||
"github.com/h44z/wg-portal/internal/domain"
|
||||
)
|
||||
|
||||
func TestInferImportedInterfaceType(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
listenPort int
|
||||
peerCount int
|
||||
expected domain.InterfaceType
|
||||
}{
|
||||
{
|
||||
name: "no peers stays unknown",
|
||||
listenPort: 51820,
|
||||
peerCount: 0,
|
||||
expected: domain.InterfaceTypeAny,
|
||||
},
|
||||
{
|
||||
name: "single peer with listen port is server",
|
||||
listenPort: 51820,
|
||||
peerCount: 1,
|
||||
expected: domain.InterfaceTypeServer,
|
||||
},
|
||||
{
|
||||
name: "single peer without listen port stays client",
|
||||
listenPort: 0,
|
||||
peerCount: 1,
|
||||
expected: domain.InterfaceTypeClient,
|
||||
},
|
||||
{
|
||||
name: "multiple peers is server",
|
||||
listenPort: 0,
|
||||
peerCount: 2,
|
||||
expected: domain.InterfaceTypeServer,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
iface := &domain.Interface{ListenPort: tt.listenPort}
|
||||
peers := make([]domain.PhysicalPeer, tt.peerCount)
|
||||
|
||||
assert.Equal(t, tt.expected, inferImportedInterfaceType(iface, peers))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportPeer_AddressMapping(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user