mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
Otherwise, actual hostname will be overriden with "localhost", which is rather confusing/bad for UX.
34 lines
881 B
Go
34 lines
881 B
Go
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)
|
|
}
|
|
})
|
|
}
|
|
}
|