fix(server): bracket an IPv6 address in an asset label with a port

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
This commit is contained in:
simple-minded 2026-12-02 20:34:09 +05:30 • committed by GitHub
parent e38f58d46e
commit 4caaeac215
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,31 @@
package server
import (
"testing"
"github.com/Autumn-27/artex/db"
)
func TestAssetLabelBracketsIPv6WithPort(t *testing.T) {
port := 8443
zero := 0
cases := []struct {
name string
asset db.Asset
want string
}{
{"ipv4 with port", db.Asset{IP: "10.0.0.5", Port: &port}, "10.0.0.5:8443"},
{"ipv6 with port", db.Asset{IP: "2001:db8::1", Port: &port}, "[2001:db8::1]:8443"},
{"ipv6 without port", db.Asset{IP: "2001:db8::1"}, "2001:db8::1"},
{"ipv6 with zero port", db.Asset{IP: "2001:db8::1", Port: &zero}, "2001:db8::1"},
{"domain with port", db.Asset{Domain: "example.com", Port: &port}, "example.com:8443"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
a := tc.asset
if got := assetLabel(&a); got != tc.want {
t.Fatalf("assetLabel = %q, want %q", got, tc.want)
}
})
}
}