Files
AdGuardHome/internal/aghnet/hostgen_test.go
Stanislav Chzhen ee91a6084f Pull request 2361: imp-test-file-names
Merge in DNS/adguard-home from imp-test-file-names to master

Squashed commit of the following:

commit a0827efdf633fba012c5eb0e0f69eaabf7629724
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Mon Mar 10 21:41:46 2025 +0300

    all: imp tests

commit 21fc274d9276ce0442572261ea39a1c018490870
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Mon Mar 10 19:40:40 2025 +0300

    all: imp test file names
2025-03-11 19:40:14 +03:00

43 lines
904 B
Go

package aghnet_test
import (
"net/netip"
"testing"
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/stretchr/testify/assert"
)
func TestGenerateHostName(t *testing.T) {
t.Run("valid", func(t *testing.T) {
testCases := []struct {
name string
want string
ip netip.Addr
}{{
name: "good_ipv4",
want: "127-0-0-1",
ip: netip.MustParseAddr("127.0.0.1"),
}, {
name: "good_ipv6",
want: "fe00-0000-0000-0000-0000-0000-0000-0001",
ip: netip.MustParseAddr("fe00::1"),
}, {
name: "4to6",
want: "1-2-3-4",
ip: netip.MustParseAddr("::ffff:1.2.3.4"),
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
hostname := aghnet.GenerateHostname(tc.ip)
assert.Equal(t, tc.want, hostname)
})
}
})
t.Run("invalid", func(t *testing.T) {
assert.Panics(t, func() { aghnet.GenerateHostname(netip.Addr{}) })
})
}