middleware/etcd: add setup_test.go (#304)

Add tests for parsing etcd Corefile stanza. Discover a bug in the code,
fix that as well.
This commit is contained in:
Miek Gieben
2016-09-26 14:43:38 +01:00
committed by GitHub
parent 6a7db541fa
commit 77947fd51a
3 changed files with 70 additions and 2 deletions

View File

@@ -100,7 +100,6 @@ func etcdParse(c *caddy.Controller) (*Etcd, bool, error) {
args[i] = h + ":53"
}
}
endpoints = args
etc.Proxy = proxy.New(args)
case "tls": // cert key cacertfile
args := c.RemainingArgs()
@@ -108,6 +107,10 @@ func etcdParse(c *caddy.Controller) (*Etcd, bool, error) {
return &Etcd{}, false, c.ArgErr()
}
tlsCertFile, tlsKeyFile, tlsCAcertFile = args[0], args[1], args[2]
default:
if c.Val() != "}" {
return &Etcd{}, false, c.Errf("unknown property '%s'", c.Val())
}
}
for c.Next() {
switch c.Val() {
@@ -144,14 +147,20 @@ func etcdParse(c *caddy.Controller) (*Etcd, bool, error) {
return &Etcd{}, false, c.ArgErr()
}
tlsCertFile, tlsKeyFile, tlsCAcertFile = args[0], args[1], args[2]
default:
if c.Val() != "}" { // TODO(miek): this feels like I'm doing it completely wrong.
return &Etcd{}, false, c.Errf("unknown property '%s'", c.Val())
}
}
}
}
client, err := newEtcdClient(endpoints, tlsCertFile, tlsKeyFile, tlsCAcertFile)
if err != nil {
return &Etcd{}, false, err
}
etc.Client = client
etc.endpoints = endpoints
return &etc, stubzones, nil
}
}