Skip to content

Commit

Permalink
Remove type from module base
Browse files Browse the repository at this point in the history
  • Loading branch information
madhuravi committed Jan 27, 2017
1 parent db82089 commit 655091b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 26 deletions.
1 change: 0 additions & 1 deletion modules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type ModuleBase struct {

// NewModuleBase configures a new ModuleBase
func NewModuleBase(
moduleType string,
name string,
service service.Host,
roles []string,
Expand Down
13 changes: 6 additions & 7 deletions modules/modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,34 @@ import (
)

func TestNewModuleBase(t *testing.T) {
mb := nmb("test", "foo", nil)
mb := nmb("foo", nil)
assert.NotNil(t, mb)
}

func TestModuleBase_Roles(t *testing.T) {
mb := nmb("test", "foo", nil)
mb := nmb("foo", nil)
assert.Nil(t, mb.Roles())
}

func TestNewModuleBase_Name(t *testing.T) {
mb := nmb("test", "foo", nil)
mb := nmb("foo", nil)
assert.Equal(t, "foo", mb.Name())
}

func TestNewModuleBase_Host(t *testing.T) {
mb := nmb("test", "foo", nil)
mb := nmb("foo", nil)
assert.NotNil(t, mb.Host())
}

func TestNewModuleBase_Tracer(t *testing.T) {
mb := nmb("test", "foo", nil)
mb := nmb("foo", nil)
assert.NotNil(t, mb.Tracer())
}

func nmb(moduleType, name string, roles []string) *ModuleBase {
func nmb(name string, roles []string) *ModuleBase {
host := service.NopHost()

return NewModuleBase(
moduleType,
name,
host,
roles,
Expand Down
5 changes: 1 addition & 4 deletions modules/rpc/yarpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ var (

type registerServiceFunc func(module *YarpcModule)

// RPCModuleType represents the type of an RPC module
const RPCModuleType = "rpc"

type yarpcConfig struct {
modules.ModuleConfig
Bind string `yaml:"bind"`
Expand All @@ -81,7 +78,7 @@ func newYarpcModule(
}

module := &YarpcModule{
ModuleBase: *modules.NewModuleBase(RPCModuleType, name, mi.Host, []string{}),
ModuleBase: *modules.NewModuleBase(name, mi.Host, []string{}),
register: reg,
config: *cfg,
}
Expand Down
5 changes: 1 addition & 4 deletions modules/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ import (
"go.uber.org/fx/service"
)

// ModuleType represents the task module type
const ModuleType = "task"

type globalBackend struct {
backend Backend
sync.RWMutex
Expand Down Expand Up @@ -71,7 +68,7 @@ func newAsyncModule(mi service.ModuleCreateInfo, backend Backend) service.Module
_globalBackendMu.Unlock()
return &AsyncModule{
Backend: backend,
modBase: *modules.NewModuleBase(ModuleType, "task", mi.Host, []string{}),
modBase: *modules.NewModuleBase("task", mi.Host, []string{}),
}
}

Expand Down
5 changes: 1 addition & 4 deletions modules/uhttp/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ import (
"github.com/pkg/errors"
)

// ModuleType is a human-friendly representation of the module
const ModuleType = "HTTP"

const (
// ContentType is the header key that contains the body type
ContentType = "Content-Type"
Expand Down Expand Up @@ -126,7 +123,7 @@ func newModule(

// TODO (madhu): Add other middleware - logging, metrics.
module := &Module{
ModuleBase: *modules.NewModuleBase(ModuleType, mi.Name, mi.Host, []string{}),
ModuleBase: *modules.NewModuleBase(mi.Name, mi.Host, []string{}),
handlers: handlers,
fcb: defaultFilterChainBuilder(mi.Host),
}
Expand Down
12 changes: 6 additions & 6 deletions service/stub_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ package service

// A StubModule implements the Module interface for testing
type StubModule struct {
Host Host
InitError error
TypeVal, NameVal string
StartError error
StopError error
Running bool
Host Host
InitError error
NameVal string
StartError error
StopError error
Running bool
}

var _ Module = &StubModule{}
Expand Down

0 comments on commit 655091b

Please sign in to comment.