2020-08-06 12:42:14 +01:00
|
|
|
package etcd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// test whether the name matches
|
|
|
|
func TestEtcdHasName(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
key string
|
|
|
|
prefix string
|
|
|
|
name string
|
2020-08-10 21:58:35 +01:00
|
|
|
domain string
|
2020-08-06 12:42:14 +01:00
|
|
|
expect bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"/micro/registry/micro/registry",
|
|
|
|
"/micro/registry",
|
|
|
|
"registry",
|
2020-08-10 21:58:35 +01:00
|
|
|
"micro",
|
2020-08-06 12:42:14 +01:00
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
2020-08-10 21:58:35 +01:00
|
|
|
"/micro/registry/micro",
|
2020-08-06 12:42:14 +01:00
|
|
|
"/micro/registry",
|
2020-08-10 21:58:35 +01:00
|
|
|
"store",
|
|
|
|
"micro",
|
2020-08-06 12:42:14 +01:00
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"/prefix/baz/*/registry",
|
|
|
|
"/prefix/baz",
|
|
|
|
"registry",
|
2020-08-10 21:58:35 +01:00
|
|
|
"*",
|
2020-08-06 12:42:14 +01:00
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
2020-08-10 21:58:35 +01:00
|
|
|
"/prefix/baz",
|
2020-08-06 12:42:14 +01:00
|
|
|
"/prefix/baz",
|
|
|
|
"store",
|
2020-08-10 21:58:35 +01:00
|
|
|
"micro",
|
2020-08-06 12:42:14 +01:00
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
2020-08-10 21:58:35 +01:00
|
|
|
"/prefix/baz/foobar/registry",
|
2020-08-06 12:42:14 +01:00
|
|
|
"/prefix/baz",
|
|
|
|
"registry",
|
2020-08-10 21:58:35 +01:00
|
|
|
"foobar",
|
2020-08-06 12:42:14 +01:00
|
|
|
true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range testCases {
|
2020-08-10 21:58:35 +01:00
|
|
|
domain, service, ok := getName(c.key, c.prefix)
|
|
|
|
if ok != c.expect {
|
|
|
|
t.Fatalf("Expected %t for %v got: %t", c.expect, c, ok)
|
|
|
|
}
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if service != c.name {
|
|
|
|
t.Fatalf("Expected service %s got %s", c.name, service)
|
|
|
|
}
|
|
|
|
if domain != c.domain {
|
|
|
|
t.Fatalf("Expected domain %s got %s", c.domain, domain)
|
2020-08-06 12:42:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|