plugin/loadbalance: add parse and tests (#1947)

Automatically submitted.
This commit is contained in:
Miek Gieben
2018-07-06 22:49:21 +01:00
committed by corbot[bot]
parent bcc749db04
commit 7c41f2ce9f
4 changed files with 71 additions and 16 deletions

View File

@@ -1,6 +1,8 @@
package loadbalance
import (
"fmt"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
clog "github.com/coredns/coredns/plugin/pkg/log"
@@ -18,8 +20,9 @@ func init() {
}
func setup(c *caddy.Controller) error {
for c.Next() {
// TODO(miek): block and option parsing
err := parse(c)
if err != nil {
return plugin.Error("loadbalance", err)
}
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
@@ -28,3 +31,20 @@ func setup(c *caddy.Controller) error {
return nil
}
func parse(c *caddy.Controller) error {
for c.Next() {
args := c.RemainingArgs()
switch len(args) {
case 0:
return nil
case 1:
if args[0] != "round_robin" {
return fmt.Errorf("unknown policy: %s", args[0])
}
return nil
}
}
return c.ArgErr()
}