mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-16 13:17:19 +02:00
internal/clientinfo: ignoring localhost entry for hostsfile mapping
Otherwise, actual hostname will be overriden with "localhost", which is rather confusing/bad for UX.
This commit is contained in:
committed by
Cuong Manh Le
parent
77c1113ff7
commit
9d2ea15346
@@ -0,0 +1,33 @@
|
||||
package clientinfo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_hostsFile_LookupHostnameByIP(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
ip string
|
||||
hostnames []string
|
||||
expectedHostname string
|
||||
}{
|
||||
{"ipv4 loopback", "127.0.0.1", []string{ipv4LocalhostName}, ""},
|
||||
{"ipv6 loopback", "::1", []string{ipv6LocalhostName, ipv6LoopbackName}, ""},
|
||||
{"non-localhost", "::1", []string{"foo"}, "foo"},
|
||||
{"multiple hostnames", "::1", []string{ipv4LocalhostName, "foo"}, "foo"},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
hf := &hostsFile{m: make(map[string][]string)}
|
||||
hf.mu.Lock()
|
||||
hf.m[tc.ip] = tc.hostnames
|
||||
hf.mu.Unlock()
|
||||
if got := hf.LookupHostnameByIP(tc.ip); got != tc.expectedHostname {
|
||||
t.Errorf("unpexpected result, want: %q, got: %q", tc.expectedHostname, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user