micro/registry/etcd/etcd_test.go

69 lines
1.0 KiB
Go
Raw Normal View History

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 23:58:35 +03:00
domain string
expect bool
}{
{
"/micro/registry/micro/registry",
"/micro/registry",
"registry",
2020-08-10 23:58:35 +03:00
"micro",
true,
},
{
2020-08-10 23:58:35 +03:00
"/micro/registry/micro",
"/micro/registry",
2020-08-10 23:58:35 +03:00
"store",
"micro",
false,
},
{
"/prefix/baz/*/registry",
"/prefix/baz",
"registry",
2020-08-10 23:58:35 +03:00
"*",
true,
},
{
2020-08-10 23:58:35 +03:00
"/prefix/baz",
"/prefix/baz",
"store",
2020-08-10 23:58:35 +03:00
"micro",
false,
},
{
2020-08-10 23:58:35 +03:00
"/prefix/baz/foobar/registry",
"/prefix/baz",
"registry",
2020-08-10 23:58:35 +03:00
"foobar",
true,
},
}
for _, c := range testCases {
2020-08-10 23:58:35 +03: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)
}
}
}