package ldaputil import "testing" func TestDialURL(t *testing.T) { tests := []struct { address string want string }{ {"8.217.205.92", "ldaps://8.217.205.92:636"}, {"ldap.opsx.vip", "ldaps://ldap.opsx.vip:636"}, {"ldap.opsx.vip:1636", "ldaps://ldap.opsx.vip:1636"}, {"2001:db8::1", "ldaps://[2001:db8::1]:636"}, {"ldap://ldap.opsx.vip", "ldap://ldap.opsx.vip:389"}, {"ldaps://ldap.opsx.vip", "ldaps://ldap.opsx.vip:636"}, {" ldaps://8.217.205.92 ", "ldaps://8.217.205.92:636"}, } for _, tt := range tests { got, err := DialURL(tt.address) if err != nil || got != tt.want { t.Errorf("DialURL(%q) = %q, %v; want %q", tt.address, got, err, tt.want) } } } func TestDialURLRejectsInvalidAddress(t *testing.T) { for _, address := range []string{"", "ldap.opsx.vip/path", "ldap.opsx.vip:", "https://ldap.opsx.vip"} { if _, err := DialURL(address); err == nil { t.Errorf("DialURL(%q) succeeded; want error", address) } } }