aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'plugin')
-rw-r--r--plugin/etcd/msg/path.go3
-rw-r--r--plugin/etcd/msg/path_test.go12
2 files changed, 15 insertions, 0 deletions
diff --git a/plugin/etcd/msg/path.go b/plugin/etcd/msg/path.go
index bfa458863..2c6cbff0f 100644
--- a/plugin/etcd/msg/path.go
+++ b/plugin/etcd/msg/path.go
@@ -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]
diff --git a/plugin/etcd/msg/path_test.go b/plugin/etcd/msg/path_test.go
index a9ec59713..a20d78333 100644
--- a/plugin/etcd/msg/path_test.go
+++ b/plugin/etcd/msg/path_test.go
@@ -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)
+ }
+}