Commit 49ee9799 authored by soulfy's avatar soulfy Committed by GitHub

fix: convert key to domain (#5064)

fix convert key to domain when key ends with '/'
parent 6377e6a9
......@@ -22,6 +22,9 @@ func Path(s, prefix string) string {
// Domain is the opposite of Path.
func Domain(s string) string {
l := strings.Split(s, "/")
if l[len(l)-1] == "" {
l = l[:len(l)-1]
}
// 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]
......
......@@ -10,3 +10,15 @@ func TestPath(t *testing.T) {
}
}
}
func TestDomain(t *testing.T) {
result1 := Domain("/skydns/local/cluster/staging/service/")
if result1 != "service.staging.cluster.local." {
t.Errorf("Failure to get domain from etcd key (with a trailing '/'), expect: 'service.staging.cluster.local.', actually get: '%s'", result1)
}
result2 := Domain("/skydns/local/cluster/staging/service")
if result2 != "service.staging.cluster.local." {
t.Errorf("Failure to get domain from etcd key (without trailing '/'), expect: 'service.staging.cluster.local.' actually get: '%s'", result2)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment