aboutsummaryrefslogtreecommitdiff
path: root/plugin/etcd/setup_test.go
diff options
context:
space:
mode:
authorGravatar Christophe de Carvalho <zaibon@users.noreply.github.com> 2019-02-01 16:30:53 +0100
committerGravatar Miek Gieben <miek@miek.nl> 2019-02-01 15:30:53 +0000
commitd878eeebbb890b2b73226e2440c73e8b2d1b102e (patch)
treeb8cc14a5834ac28eebc0c809d87e063f482c2c91 /plugin/etcd/setup_test.go
parentb455f86824a1c2108b305589190e964b5528fed3 (diff)
downloadcoredns-d878eeebbb890b2b73226e2440c73e8b2d1b102e.tar.gz
coredns-d878eeebbb890b2b73226e2440c73e8b2d1b102e.tar.zst
coredns-d878eeebbb890b2b73226e2440c73e8b2d1b102e.zip
support etcd credentials in etcd plugin (#2442)
* support etcd credentials in etcd plugin fixes #2441 * try to fix cleanup of authentication
Diffstat (limited to 'plugin/etcd/setup_test.go')
-rw-r--r--plugin/etcd/setup_test.go54
1 files changed, 47 insertions, 7 deletions
diff --git a/plugin/etcd/setup_test.go b/plugin/etcd/setup_test.go
index 0696dc3e3..29018d623 100644
--- a/plugin/etcd/setup_test.go
+++ b/plugin/etcd/setup_test.go
@@ -14,43 +14,69 @@ func TestSetupEtcd(t *testing.T) {
expectedPath string
expectedEndpoint []string
expectedErrContent string // substring from the expected error. Empty for positive cases.
+ username string
+ password string
}{
// positive
{
- `etcd`, false, "skydns", []string{"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"}, "",
+}`, false, "skydns", []string{"http://localhost:2379", "http://localhost:3379", "http://localhost:4379"}, "", "", "",
},
{
`etcd skydns.local {
endpoint localhost:300
}
-`, false, "skydns", []string{"localhost:300"}, "",
+`, false, "skydns", []string{"localhost:300"}, "", "", "",
},
//test for upstream
{
`etcd {
endpoint localhost:300
upstream 8.8.8.8:53 8.8.4.4:53
-}`, false, "skydns", []string{"localhost:300"}, "",
+}`, false, "skydns", []string{"localhost:300"}, "", "", "",
},
//test for optional upstream address
{
`etcd {
endpoint localhost:300
upstream
-}`, false, "skydns", []string{"localhost:300"}, "",
+}`, false, "skydns", []string{"localhost:300"}, "", "", "",
},
// negative
{
`etcd {
endpoints localhost:300
}
-`, true, "", []string{""}, "unknown property 'endpoints'",
+`, true, "", []string{""}, "unknown property 'endpoints'", "", "",
+ },
+ // with valid credentials
+ {
+ `etcd {
+ endpoint http://localhost:2379
+ credentials username password
+ }
+ `, false, "skydns", []string{"http://localhost:2379"}, "", "username", "password",
+ },
+ // with credentials, missing password
+ {
+ `etcd {
+ endpoint http://localhost:2379
+ credentials username
+ }
+ `, true, "skydns", []string{"http://localhost:2379"}, "credentials requires 2 arguments", "username", "",
+ },
+ // with credentials, missing username and password
+ {
+ `etcd {
+ endpoint http://localhost:2379
+ credentials
+ }
+ `, true, "skydns", []string{"http://localhost:2379"}, "Wrong argument count", "", "",
},
}
@@ -69,7 +95,7 @@ func TestSetupEtcd(t *testing.T) {
}
if !strings.Contains(err.Error(), test.expectedErrContent) {
- t.Errorf("Test %d: Expected error to contain: %v, found error: %v, input: %s", i, test.expectedErrContent, err, test.input)
+ t.Errorf("Test %d: Expected error to contain: %v, found error: %v, input: %s", i, test.expectedErrContent, err.Error(), test.input)
continue
}
}
@@ -87,5 +113,19 @@ func TestSetupEtcd(t *testing.T) {
}
}
}
+
+ if !test.shouldErr {
+ if test.username != "" {
+ if etcd.Client.Username != test.username {
+ t.Errorf("Etcd username not correctly set for input %s. Excpeted: '%+v', actual: '%+v'", test.input, test.username, etcd.Client.Username)
+ }
+ }
+ if test.password != "" {
+ if etcd.Client.Password != test.password {
+ t.Errorf("Etcd password not correctly set for input %s. Excpeted: '%+v', actual: '%+v'", test.input, test.password, etcd.Client.Password)
+ }
+ }
+ }
+
}
}