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

api: make New to receive Container as a required param #872

Merged
merged 4 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 5 additions & 22 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,12 @@ type API struct {
container container.Container
}

// Option is a configuration func for MESG.
type Option func(*API)

// New creates a new API with given options.
func New(db database.ServiceDB, execDB database.ExecutionDB, options ...Option) (*API, error) {
a := &API{db: db, execDB: execDB}
for _, option := range options {
option(a)
}
if a.container == nil {
var err error
a.container, err = container.New()
if err != nil {
return nil, err
}
}
return a, nil
}

// ContainerOption configures underlying container access API.
func ContainerOption(container container.Container) Option {
return func(a *API) {
a.container = container
func New(c container.Container, db database.ServiceDB, execDB database.ExecutionDB) *API {
return &API{
container: c,
db: db,
execDB: execDB,
}
}

Expand Down
3 changes: 1 addition & 2 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func newTesting(t *testing.T) (*API, *apiTesting) {
execDB, err := database.NewExecutionDB(execdbname)
require.NoError(t, err)

a, err := New(db, execDB, ContainerOption(containerMock))
require.NoError(t, err)
a := New(containerMock, db, execDB)

return a, &apiTesting{
T: t,
Expand Down
5 changes: 1 addition & 4 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ func initDependencies() (*dependencies, error) {
}

// init api.
api, err := api.New(serviceDB, executionDB, api.ContainerOption(c))
if err != nil {
return nil, err
}
api := api.New(c, serviceDB, executionDB)

return &dependencies{
config: config,
Expand Down
3 changes: 1 addition & 2 deletions interface/grpc/core/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ func newServerWithContainer(t *testing.T, c container.Container) (*Server, func(
execDB, err := database.NewExecutionDB(execdbname)
require.NoError(t, err)

a, err := api.New(db, execDB, api.ContainerOption(c))
require.NoError(t, err)
a := api.New(c, db, execDB)

server := NewServer(a)

Expand Down
4 changes: 1 addition & 3 deletions interface/grpc/service/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ func newServer(t *testing.T) (*Server, func()) {
execDB, err := database.NewExecutionDB(execdbname)
require.NoError(t, err)

a, err := api.New(db, execDB)
require.NoError(t, err)

a := api.New(nil, db, execDB)
server := NewServer(a)

closer := func() {
Expand Down