Update etcd/README.md for multiple endpoints, and add additional test cases (#1277)

This fix tries to address the issue raised in 1275 to clarify
the syntax for multiple endpoints specification.

This fix also adds additional test cases to demo the usage.

This fix fixes 1275.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang 2017-12-05 12:02:37 -06:00 committed by Miek Gieben
parent 5bafa6d97f
commit 0baab055df
2 changed files with 27 additions and 6 deletions

View file

@ -79,6 +79,14 @@ when resolving external pointing CNAMEs.
} }
~~~ ~~~
Multiple endpoints are supported as well.
~~~
etcd skydns.local {
endpoint http://localhost:2379 http://localhost:4001
...
~~~
### Reverse zones ### Reverse zones

View file

@ -12,25 +12,31 @@ func TestSetupEtcd(t *testing.T) {
input string input string
shouldErr bool shouldErr bool
expectedPath string expectedPath string
expectedEndpoint string expectedEndpoint []string
expectedErrContent string // substring from the expected error. Empty for positive cases. expectedErrContent string // substring from the expected error. Empty for positive cases.
}{ }{
// positive // positive
{ {
`etcd`, false, "skydns", "http://localhost:2379", "", `etcd`, false, "skydns", []string{"http://localhost:2379"}, "",
},
{
`etcd {
endpoint http://localhost:2379 http://localhost:3379 http://localhost:4379
}`, false, "skydns", []string{"http://localhost:2379", "http://localhost:3379", "http://localhost:4379"}, "",
}, },
{ {
`etcd skydns.local { `etcd skydns.local {
endpoint localhost:300 endpoint localhost:300
} }
`, false, "skydns", "localhost:300", "", `, false, "skydns", []string{"localhost:300"}, "",
}, },
// negative // negative
{ {
`etcd { `etcd {
endpoints localhost:300 endpoints localhost:300
} }
`, true, "", "", "unknown property 'endpoints'", `, true, "", []string{""}, "unknown property 'endpoints'",
}, },
} }
@ -57,8 +63,15 @@ func TestSetupEtcd(t *testing.T) {
if !test.shouldErr && etcd.PathPrefix != test.expectedPath { if !test.shouldErr && etcd.PathPrefix != test.expectedPath {
t.Errorf("Etcd not correctly set for input %s. Expected: %s, actual: %s", test.input, test.expectedPath, etcd.PathPrefix) t.Errorf("Etcd not correctly set for input %s. Expected: %s, actual: %s", test.input, test.expectedPath, etcd.PathPrefix)
} }
if !test.shouldErr && etcd.endpoints[0] != test.expectedEndpoint { // only checks the first if !test.shouldErr {
t.Errorf("Etcd not correctly set for input %s. Expected: '%s', actual: '%s'", test.input, test.expectedEndpoint, etcd.endpoints[0]) if len(etcd.endpoints) != len(test.expectedEndpoint) {
t.Errorf("Etcd not correctly set for input %s. Expected: '%+v', actual: '%+v'", test.input, test.expectedEndpoint, etcd.endpoints)
}
for i, endpoint := range etcd.endpoints {
if endpoint != test.expectedEndpoint[i] {
t.Errorf("Etcd not correctly set for input %s. Expected: '%+v', actual: '%+v'", test.input, test.expectedEndpoint, etcd.endpoints)
}
}
} }
} }
} }