mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-12-03 13:11:05 +00:00
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:
parent
e38f58d46e
commit
4caaeac215
1 changed files with 31 additions and 0 deletions
31
server/asset_label_test.go
Normal file
31
server/asset_label_test.go
Normal 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue