mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #14586 from serathius/pattern
tests: Use bash like patterns in TestAuthority instead of string fo…
This commit is contained in:
commit
a5fb57b485
@ -32,52 +32,47 @@ import (
|
||||
|
||||
func TestAuthority(t *testing.T) {
|
||||
tcs := []struct {
|
||||
name string
|
||||
useTLS bool
|
||||
useInsecureTLS bool
|
||||
// Pattern used to generate endpoints for client. Fields filled
|
||||
// %d - will be filled with member grpc port
|
||||
clientURLPattern string
|
||||
|
||||
// Pattern used to validate authority received by server. Fields filled:
|
||||
// %d - will be filled with first member grpc port
|
||||
name string
|
||||
useTLS bool
|
||||
useInsecureTLS bool
|
||||
clientURLPattern string
|
||||
expectAuthorityPattern string
|
||||
}{
|
||||
{
|
||||
name: "http://domain[:port]",
|
||||
clientURLPattern: "http://localhost:%d",
|
||||
expectAuthorityPattern: "localhost:%d",
|
||||
clientURLPattern: "http://localhost:${MEMBER_PORT}",
|
||||
expectAuthorityPattern: "localhost:${MEMBER_PORT}",
|
||||
},
|
||||
{
|
||||
name: "http://address[:port]",
|
||||
clientURLPattern: "http://127.0.0.1:%d",
|
||||
expectAuthorityPattern: "127.0.0.1:%d",
|
||||
clientURLPattern: "http://127.0.0.1:${MEMBER_PORT}",
|
||||
expectAuthorityPattern: "127.0.0.1:${MEMBER_PORT}",
|
||||
},
|
||||
{
|
||||
name: "https://domain[:port] insecure",
|
||||
useTLS: true,
|
||||
useInsecureTLS: true,
|
||||
clientURLPattern: "https://localhost:%d",
|
||||
expectAuthorityPattern: "localhost:%d",
|
||||
clientURLPattern: "https://localhost:${MEMBER_PORT}",
|
||||
expectAuthorityPattern: "localhost:${MEMBER_PORT}",
|
||||
},
|
||||
{
|
||||
name: "https://address[:port] insecure",
|
||||
useTLS: true,
|
||||
useInsecureTLS: true,
|
||||
clientURLPattern: "https://127.0.0.1:%d",
|
||||
expectAuthorityPattern: "127.0.0.1:%d",
|
||||
clientURLPattern: "https://127.0.0.1:${MEMBER_PORT}",
|
||||
expectAuthorityPattern: "127.0.0.1:${MEMBER_PORT}",
|
||||
},
|
||||
{
|
||||
name: "https://domain[:port]",
|
||||
useTLS: true,
|
||||
clientURLPattern: "https://localhost:%d",
|
||||
expectAuthorityPattern: "localhost:%d",
|
||||
clientURLPattern: "https://localhost:${MEMBER_PORT}",
|
||||
expectAuthorityPattern: "localhost:${MEMBER_PORT}",
|
||||
},
|
||||
{
|
||||
name: "https://address[:port]",
|
||||
useTLS: true,
|
||||
clientURLPattern: "https://127.0.0.1:%d",
|
||||
expectAuthorityPattern: "127.0.0.1:%d",
|
||||
clientURLPattern: "https://127.0.0.1:${MEMBER_PORT}",
|
||||
expectAuthorityPattern: "127.0.0.1:${MEMBER_PORT}",
|
||||
},
|
||||
}
|
||||
for _, tc := range tcs {
|
||||
@ -110,7 +105,7 @@ func TestAuthority(t *testing.T) {
|
||||
}
|
||||
|
||||
testutils.ExecuteWithTimeout(t, 5*time.Second, func() {
|
||||
assertAuthority(t, fmt.Sprintf(tc.expectAuthorityPattern, 20000), epc)
|
||||
assertAuthority(t, strings.Replace(tc.expectAuthorityPattern, "${MEMBER_PORT}", "20000", -1), epc)
|
||||
})
|
||||
})
|
||||
|
||||
@ -123,12 +118,7 @@ func templateEndpoints(t *testing.T, pattern string, clus *e2e.EtcdProcessCluste
|
||||
var endpoints []string
|
||||
for i := 0; i < clus.Cfg.ClusterSize; i++ {
|
||||
ent := pattern
|
||||
if strings.Contains(ent, "%d") {
|
||||
ent = fmt.Sprintf(ent, e2e.EtcdProcessBasePort+i*5)
|
||||
}
|
||||
if strings.Contains(ent, "%") {
|
||||
t.Fatalf("Failed to template pattern, %% symbol left %q", ent)
|
||||
}
|
||||
ent = strings.Replace(ent, "${MEMBER_PORT}", fmt.Sprintf("%d", e2e.EtcdProcessBasePort+i*5), -1)
|
||||
endpoints = append(endpoints, ent)
|
||||
}
|
||||
return endpoints
|
||||
|
@ -29,67 +29,60 @@ import (
|
||||
|
||||
func TestAuthority(t *testing.T) {
|
||||
tcs := []struct {
|
||||
name string
|
||||
useTCP bool
|
||||
useTLS bool
|
||||
// Pattern used to generate endpoints for client. Fields filled
|
||||
// %d - will be filled with member grpc port
|
||||
// %s - will be filled with member name
|
||||
clientURLPattern string
|
||||
|
||||
// Pattern used to validate authority received by server. Fields filled:
|
||||
// %d - will be filled with first member grpc port
|
||||
// %s - will be filled with first member name
|
||||
name string
|
||||
useTCP bool
|
||||
useTLS bool
|
||||
clientURLPattern string
|
||||
expectAuthorityPattern string
|
||||
}{
|
||||
{
|
||||
name: "unix:path",
|
||||
clientURLPattern: "unix:localhost:%s",
|
||||
expectAuthorityPattern: "localhost:%s",
|
||||
clientURLPattern: "unix:localhost:${MEMBER_NAME}",
|
||||
expectAuthorityPattern: "localhost:${MEMBER_NAME}",
|
||||
},
|
||||
{
|
||||
name: "unix://absolute_path",
|
||||
clientURLPattern: "unix://localhost:%s",
|
||||
expectAuthorityPattern: "localhost:%s",
|
||||
clientURLPattern: "unix://localhost:${MEMBER_NAME}",
|
||||
expectAuthorityPattern: "localhost:${MEMBER_NAME}",
|
||||
},
|
||||
// "unixs" is not standard schema supported by etcd
|
||||
{
|
||||
name: "unixs:absolute_path",
|
||||
useTLS: true,
|
||||
clientURLPattern: "unixs:localhost:%s",
|
||||
expectAuthorityPattern: "localhost:%s",
|
||||
clientURLPattern: "unixs:localhost:${MEMBER_NAME}",
|
||||
expectAuthorityPattern: "localhost:${MEMBER_NAME}",
|
||||
},
|
||||
{
|
||||
name: "unixs://absolute_path",
|
||||
useTLS: true,
|
||||
clientURLPattern: "unixs://localhost:%s",
|
||||
expectAuthorityPattern: "localhost:%s",
|
||||
clientURLPattern: "unixs://localhost:${MEMBER_NAME}",
|
||||
expectAuthorityPattern: "localhost:${MEMBER_NAME}",
|
||||
},
|
||||
{
|
||||
name: "http://domain[:port]",
|
||||
useTCP: true,
|
||||
clientURLPattern: "http://localhost:%d",
|
||||
expectAuthorityPattern: "localhost:%d",
|
||||
clientURLPattern: "http://localhost:${MEMBER_PORT}",
|
||||
expectAuthorityPattern: "localhost:${MEMBER_PORT}",
|
||||
},
|
||||
{
|
||||
name: "https://domain[:port]",
|
||||
useTLS: true,
|
||||
useTCP: true,
|
||||
clientURLPattern: "https://localhost:%d",
|
||||
expectAuthorityPattern: "localhost:%d",
|
||||
clientURLPattern: "https://localhost:${MEMBER_PORT}",
|
||||
expectAuthorityPattern: "localhost:${MEMBER_PORT}",
|
||||
},
|
||||
{
|
||||
name: "http://address[:port]",
|
||||
useTCP: true,
|
||||
clientURLPattern: "http://127.0.0.1:%d",
|
||||
expectAuthorityPattern: "127.0.0.1:%d",
|
||||
clientURLPattern: "http://127.0.0.1:${MEMBER_PORT}",
|
||||
expectAuthorityPattern: "127.0.0.1:${MEMBER_PORT}",
|
||||
},
|
||||
{
|
||||
name: "https://address[:port]",
|
||||
useTCP: true,
|
||||
useTLS: true,
|
||||
clientURLPattern: "https://127.0.0.1:%d",
|
||||
expectAuthorityPattern: "127.0.0.1:%d",
|
||||
clientURLPattern: "https://127.0.0.1:${MEMBER_PORT}",
|
||||
expectAuthorityPattern: "127.0.0.1:${MEMBER_PORT}",
|
||||
},
|
||||
}
|
||||
for _, tc := range tcs {
|
||||
@ -153,15 +146,8 @@ func templateEndpoints(t *testing.T, pattern string, clus *integration.Cluster)
|
||||
var endpoints []string
|
||||
for _, m := range clus.Members {
|
||||
ent := pattern
|
||||
if strings.Contains(ent, "%d") {
|
||||
ent = fmt.Sprintf(ent, integration.GrpcPortNumber(m.UniqNumber, m.MemberNumber))
|
||||
}
|
||||
if strings.Contains(ent, "%s") {
|
||||
ent = fmt.Sprintf(ent, m.Name)
|
||||
}
|
||||
if strings.Contains(ent, "%") {
|
||||
t.Fatalf("Failed to template pattern, %% symbol left %q", ent)
|
||||
}
|
||||
ent = strings.Replace(ent, "${MEMBER_PORT}", fmt.Sprintf("%d", integration.GrpcPortNumber(m.UniqNumber, m.MemberNumber)), -1)
|
||||
ent = strings.Replace(ent, "${MEMBER_NAME}", m.Name, -1)
|
||||
endpoints = append(endpoints, ent)
|
||||
}
|
||||
return endpoints
|
||||
@ -170,15 +156,8 @@ func templateEndpoints(t *testing.T, pattern string, clus *integration.Cluster)
|
||||
func templateAuthority(t *testing.T, pattern string, m *integration.Member) string {
|
||||
t.Helper()
|
||||
authority := pattern
|
||||
if strings.Contains(authority, "%d") {
|
||||
authority = fmt.Sprintf(authority, integration.GrpcPortNumber(m.UniqNumber, m.MemberNumber))
|
||||
}
|
||||
if strings.Contains(authority, "%s") {
|
||||
authority = fmt.Sprintf(authority, m.Name)
|
||||
}
|
||||
if strings.Contains(authority, "%") {
|
||||
t.Fatalf("Failed to template pattern, %% symbol left %q", authority)
|
||||
}
|
||||
authority = strings.Replace(authority, "${MEMBER_PORT}", fmt.Sprintf("%d", integration.GrpcPortNumber(m.UniqNumber, m.MemberNumber)), -1)
|
||||
authority = strings.Replace(authority, "${MEMBER_NAME}", m.Name, -1)
|
||||
return authority
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user