mirror of
https://github.com/minio/minio.git
synced 2026-02-04 18:00:15 -05:00
* Add more tests to UnPath function * Revert implementation on dns.msgUnPath. Fixes: #21541
This commit is contained in:
@@ -49,16 +49,9 @@ func dnsJoin(labels ...string) string {
|
|||||||
|
|
||||||
// msgUnPath converts a etcd path to domainName.
|
// msgUnPath converts a etcd path to domainName.
|
||||||
func msgUnPath(s string) string {
|
func msgUnPath(s string) string {
|
||||||
l := strings.Split(s, etcdPathSeparator)
|
ks := strings.Split(strings.Trim(s, etcdPathSeparator), etcdPathSeparator)
|
||||||
if l[len(l)-1] == "" {
|
for i, j := 0, len(ks)-1; i < j; i, j = i+1, j-1 {
|
||||||
l = l[:len(l)-1]
|
ks[i], ks[j] = ks[j], ks[i]
|
||||||
}
|
}
|
||||||
if len(l) < 2 {
|
return strings.Join(ks, ".")
|
||||||
return s
|
|
||||||
}
|
|
||||||
// start with 1, to strip /skydns
|
|
||||||
for i, j := 1, len(l)-1; i < j; i, j = i+1, j-1 {
|
|
||||||
l[i], l[j] = l[j], l[i]
|
|
||||||
}
|
|
||||||
return dnsJoin(l[1 : len(l)-1]...)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,12 +48,27 @@ func TestPath(t *testing.T) {
|
|||||||
|
|
||||||
func TestUnPath(t *testing.T) {
|
func TestUnPath(t *testing.T) {
|
||||||
result1 := msgUnPath("/skydns/local/cluster/staging/service/")
|
result1 := msgUnPath("/skydns/local/cluster/staging/service/")
|
||||||
if result1 != "service.staging.cluster.local." {
|
if result1 != "service.staging.cluster.local.skydns" {
|
||||||
t.Errorf("Failure to get domain from etcd key (with a trailing '/'), expect: 'service.staging.cluster.local.', actually get: '%s'", result1)
|
t.Errorf("Failure to get domain from etcd key (with a trailing '/'), expect: 'service.staging.cluster.local.', actually get: '%s'", result1)
|
||||||
}
|
}
|
||||||
|
|
||||||
result2 := msgUnPath("/skydns/local/cluster/staging/service")
|
result2 := msgUnPath("/skydns/local/cluster/staging/service")
|
||||||
if result2 != "service.staging.cluster.local." {
|
if result2 != "service.staging.cluster.local.skydns" {
|
||||||
t.Errorf("Failure to get domain from etcd key (without trailing '/'), expect: 'service.staging.cluster.local.' actually get: '%s'", result2)
|
t.Errorf("Failure to get domain from etcd key (without trailing '/'), expect: 'service.staging.cluster.local.' actually get: '%s'", result2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result3 := msgUnPath("/singleleveldomain/")
|
||||||
|
if result3 != "singleleveldomain" {
|
||||||
|
t.Errorf("Failure to get domain from etcd key (with leading and trailing '/'), expect: 'singleleveldomain.' actually get: '%s'", result3)
|
||||||
|
}
|
||||||
|
|
||||||
|
result4 := msgUnPath("/singleleveldomain")
|
||||||
|
if result4 != "singleleveldomain" {
|
||||||
|
t.Errorf("Failure to get domain from etcd key (without trailing '/'), expect: 'singleleveldomain.' actually get: '%s'", result4)
|
||||||
|
}
|
||||||
|
|
||||||
|
result5 := msgUnPath("singleleveldomain")
|
||||||
|
if result5 != "singleleveldomain" {
|
||||||
|
t.Errorf("Failure to get domain from etcd key (without leading and trailing '/'), expect: 'singleleveldomain.' actually get: '%s'", result5)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user