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

Making lib/backend/client.getFactory public #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/backend/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ func Register(name string, factory ClientFactory) {
_factories[name] = factory
}

// getFactory returns backend client factory given client name.
func getFactory(name string) (ClientFactory, error) {
// GetFactory returns backend client factory given client name.
// This function should stay public to allow for wrapper custom backends.
func GetFactory(name string) (ClientFactory, error) {
factory, ok := _factories[name]
if !ok {
return nil, fmt.Errorf("no backend client defined with name %s", name)
Expand Down
32 changes: 32 additions & 0 deletions lib/backend/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package backend

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestRegisterAndGetFactory(t *testing.T) {
t.Run("round-trip", func(t *testing.T) {
name := "dummy"
factory := &dummyFactory{}

Register(name, factory)
roundTrip, err := GetFactory(name)

assert.NoError(t, err)
assert.Equal(t, factory, roundTrip)
})

t.Run("GetFactory errors out on missing factory", func(t *testing.T) {
_, err := GetFactory("i_dont_exist")

assert.Error(t, err)
})
}

type dummyFactory struct{}

func (f *dummyFactory) Create(config interface{}, authConfig interface{}) (Client, error) {
return nil, nil
}
2 changes: 1 addition & 1 deletion lib/backend/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewManager(configs []Config, auth AuthConfig) (*Manager, error) {
var backendConfig interface{}
for name, backendConfig = range config.Backend { // Pull the only key/value out of map
}
factory, err := getFactory(name)
factory, err := GetFactory(name)
if err != nil {
return nil, fmt.Errorf("get backend client factory: %s", err)
}
Expand Down