Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin/clouddns: remove initialization from init #3349

Merged
merged 2 commits into from Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 15 additions & 19 deletions plugin/clouddns/setup.go
Expand Up @@ -17,27 +17,23 @@ import (

var log = clog.NewWithPlugin("clouddns")

func init() {
plugin.Register("clouddns",
func(c *caddy.Controller) error {
f := func(ctx context.Context, opt option.ClientOption) (gcpDNS, error) {
var err error
var client *gcp.Service
if opt != nil {
client, err = gcp.NewService(ctx, opt)
} else {
// if credentials file is not provided in the Corefile
// authenticate the client using env variables
client, err = gcp.NewService(ctx)
}
return gcpClient{client}, err
}
return setup(c, f)
},
)
func init() { plugin.Register("clouddns", setup) }

// exposed for testing
var f = func(ctx context.Context, opt option.ClientOption) (gcpDNS, error) {
var err error
var client *gcp.Service
if opt != nil {
client, err = gcp.NewService(ctx, opt)
} else {
// if credentials file is not provided in the Corefile
// authenticate the client using env variables
client, err = gcp.NewService(ctx)
}
return gcpClient{client}, err
}

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() {
keyPairs := map[string]struct{}{}
keys := map[string][]string{}
Expand Down
4 changes: 2 additions & 2 deletions plugin/clouddns/setup_test.go
Expand Up @@ -9,7 +9,7 @@ import (
)

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
}

Expand Down Expand Up @@ -41,7 +41,7 @@ func TestSetupCloudDNS(t *testing.T) {

for _, test := range tests {
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)
}
}
Expand Down