Fix single-peer interface import mode (#695)

Co-authored-by: nbk1982 <16351736+nbk1982@users.noreply.github.com>
This commit is contained in:
nbk1982
2026-05-23 15:31:37 -03:00
committed by GitHub
parent 0cf04d07e0
commit 8fe50bf7dd
2 changed files with 58 additions and 10 deletions

View File

@@ -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