From 0baab055df5ff263a50132a9e8201b8e25b4d22d Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Tue, 5 Dec 2017 12:02:37 -0600 Subject: [PATCH] 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 --- plugin/etcd/README.md | 8 ++++++++ plugin/etcd/setup_test.go | 25 +++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/plugin/etcd/README.md b/plugin/etcd/README.md index f8e3353ca..7cc396f53 100644 --- a/plugin/etcd/README.md +++ b/plugin/etcd/README.md @@ -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 diff --git a/plugin/etcd/setup_test.go b/plugin/etcd/setup_test.go index 833e2ba4c..517aeea54 100644 --- a/plugin/etcd/setup_test.go +++ b/plugin/etcd/setup_test.go @@ -12,25 +12,31 @@ func TestSetupEtcd(t *testing.T) { input string shouldErr bool expectedPath string - expectedEndpoint string + expectedEndpoint []string expectedErrContent string // substring from the expected error. Empty for positive cases. }{ // 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 { endpoint localhost:300 } -`, false, "skydns", "localhost:300", "", +`, false, "skydns", []string{"localhost:300"}, "", }, // negative { `etcd { 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 { 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 - t.Errorf("Etcd not correctly set for input %s. Expected: '%s', actual: '%s'", test.input, test.expectedEndpoint, etcd.endpoints[0]) + if !test.shouldErr { + 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) + } + } } } }