Commit 8fde7407 authored by Miek Gieben's avatar Miek Gieben Committed by Yong Tang

plugin/clouddns: remove initialization from init (#3349)

* plugin/clouddns: remove initialization from init

Init should just call the plugin.Register with a setup function.

Fixes: #3343
Signed-off-by: default avatarMiek Gieben <miek@miek.nl>

* Fix placement for var f
Signed-off-by: default avatarMiek Gieben <miek@miek.nl>
parent 0da2c0c3
...@@ -17,10 +17,10 @@ import ( ...@@ -17,10 +17,10 @@ import (
var log = clog.NewWithPlugin("clouddns") var log = clog.NewWithPlugin("clouddns")
func init() { func init() { plugin.Register("clouddns", setup) }
plugin.Register("clouddns",
func(c *caddy.Controller) error { // exposed for testing
f := func(ctx context.Context, opt option.ClientOption) (gcpDNS, error) { var f = func(ctx context.Context, opt option.ClientOption) (gcpDNS, error) {
var err error var err error
var client *gcp.Service var client *gcp.Service
if opt != nil { if opt != nil {
...@@ -31,13 +31,9 @@ func init() { ...@@ -31,13 +31,9 @@ func init() {
client, err = gcp.NewService(ctx) client, err = gcp.NewService(ctx)
} }
return gcpClient{client}, err return gcpClient{client}, err
}
return setup(c, f)
},
)
} }
func setup(c *caddy.Controller, f func(ctx context.Context, opt option.ClientOption) (gcpDNS, error)) error { func setup(c *caddy.Controller) error {
for c.Next() { for c.Next() {
keyPairs := map[string]struct{}{} keyPairs := map[string]struct{}{}
keys := map[string][]string{} keys := map[string][]string{}
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
) )
func TestSetupCloudDNS(t *testing.T) { func TestSetupCloudDNS(t *testing.T) {
f := func(ctx context.Context, opt option.ClientOption) (gcpDNS, error) { f = func(ctx context.Context, opt option.ClientOption) (gcpDNS, error) {
return fakeGCPClient{}, nil return fakeGCPClient{}, nil
} }
...@@ -41,7 +41,7 @@ func TestSetupCloudDNS(t *testing.T) { ...@@ -41,7 +41,7 @@ func TestSetupCloudDNS(t *testing.T) {
for _, test := range tests { for _, test := range tests {
c := caddy.NewTestController("dns", test.body) c := caddy.NewTestController("dns", test.body)
if err := setup(c, f); (err == nil) == test.expectedError { if err := setup(c); (err == nil) == test.expectedError {
t.Errorf("Unexpected errors: %v", err) t.Errorf("Unexpected errors: %v", err)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment