Skip to content

Commit

Permalink
Rename 'work.DataMapper' to 'work.UnitDataMapper'. (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
fr33r authored Oct 9, 2022
1 parent d300bff commit 7fee27a
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ mocks-v3:

mocks-v4:
@echo making v4 mocks...
@mockgen -source=v4/data_mapper.go -destination=v4/internal/mock/data_mapper.go -package=mock -mock_names=DataMapper=DataMapper
@mockgen -source=v4/unit_data_mapper.go -destination=v4/internal/mock/unit_data_mapper.go -package=mock -mock_names=UnitDataMapper=UnitDataMapper
@echo done!

mocks: mocks-v3 mocks-v4
Expand Down
10 changes: 5 additions & 5 deletions v4/best_effort_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type BestEffortUnitTestSuite struct {
sut work.Unit

// mocks.
mappers map[work.TypeName]*mock.DataMapper
mappers map[work.TypeName]*mock.UnitDataMapper
scope tally.TestScope
mc *gomock.Controller

Expand Down Expand Up @@ -116,12 +116,12 @@ func (s *BestEffortUnitTestSuite) Setup() {

// initialize mocks.
s.mc = gomock.NewController(s.T())
s.mappers = make(map[work.TypeName]*mock.DataMapper)
s.mappers[fooTypeName] = mock.NewDataMapper(s.mc)
s.mappers[barTypeName] = mock.NewDataMapper(s.mc)
s.mappers = make(map[work.TypeName]*mock.UnitDataMapper)
s.mappers[fooTypeName] = mock.NewUnitDataMapper(s.mc)
s.mappers[barTypeName] = mock.NewUnitDataMapper(s.mc)

// construct SUT.
dm := make(map[work.TypeName]work.DataMapper)
dm := make(map[work.TypeName]work.UnitDataMapper)
for t, m := range s.mappers {
dm[t] = m
}
Expand Down
92 changes: 92 additions & 0 deletions v4/internal/mock/unit_data_mapper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions v4/sql_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type SQLUnitTestSuite struct {
_db sqlmock.Sqlmock
scope tally.TestScope
mc *gomock.Controller
mappers map[work.TypeName]*mock.DataMapper
mappers map[work.TypeName]*mock.UnitDataMapper

// metrics scope names and tags.
scopePrefix string
Expand Down Expand Up @@ -112,16 +112,16 @@ func (s *SQLUnitTestSuite) Setup() {

// initialize mocks.
s.mc = gomock.NewController(s.T())
s.mappers = make(map[work.TypeName]*mock.DataMapper)
s.mappers[fooTypeName] = mock.NewDataMapper(s.mc)
s.mappers[barTypeName] = mock.NewDataMapper(s.mc)
s.mappers = make(map[work.TypeName]*mock.UnitDataMapper)
s.mappers[fooTypeName] = mock.NewUnitDataMapper(s.mc)
s.mappers[barTypeName] = mock.NewUnitDataMapper(s.mc)

var err error
s.db, s._db, err = sqlmock.New()
s.Require().NoError(err)

// construct SUT.
dm := make(map[work.TypeName]work.DataMapper)
dm := make(map[work.TypeName]work.UnitDataMapper)
for t, m := range s.mappers {
dm[t] = m
}
Expand Down
2 changes: 1 addition & 1 deletion v4/unit/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ var (
type MapperContext = work.MapperContext

// DataMapper represents a creator, modifier, and deleter of entities.
type DataMapper = work.DataMapper
type DataMapper = work.UnitDataMapper

// DataMapperFunc represents a data mapper function that performs a single
// operation, such as insert, update, or delete.
Expand Down
2 changes: 1 addition & 1 deletion v4/data_mapper.go → v4/unit_data_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package work
import "context"

// DataMapper represents a creator, modifier, and deleter of entities.
type DataMapper interface {
type UnitDataMapper interface {
Insert(context.Context, MapperContext, ...interface{}) error
Update(context.Context, MapperContext, ...interface{}) error
Delete(context.Context, MapperContext, ...interface{}) error
Expand Down
2 changes: 1 addition & 1 deletion v4/unit_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ var (
}

// UnitDataMappers specifies the option to provide the data mappers for the work unit.
UnitDataMappers = func(dm map[TypeName]DataMapper) UnitOption {
UnitDataMappers = func(dm map[TypeName]UnitDataMapper) UnitOption {
return func(o *UnitOptions) {
if dm == nil || len(dm) == 0 {
return
Expand Down
4 changes: 2 additions & 2 deletions v4/unit_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *UnitOptionsTestSuite) TestUnitDBOption() {

func (s *UnitOptionsTestSuite) TestUnitDataMappers_Nil() {
// arrange.
var dm map[work.TypeName]work.DataMapper
var dm map[work.TypeName]work.UnitDataMapper

// action.
work.UnitDataMappers(dm)(s.sut)
Expand All @@ -70,7 +70,7 @@ func (s *UnitOptionsTestSuite) TestUnitDataMappers_Nil() {

func (s *UnitOptionsTestSuite) TestUnitDataMappers_NotNil() {
// arrange.
dm := make(map[work.TypeName]work.DataMapper)
dm := make(map[work.TypeName]work.UnitDataMapper)
mc := gomock.NewController(s.T())
fooTypeName := work.TypeNameOf(test.Foo{})
dm[fooTypeName] = mock.NewDataMapper(mc)
Expand Down
32 changes: 16 additions & 16 deletions v4/unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type UnitTestSuite struct {

// mocks.
scope tally.TestScope
mappers map[work.TypeName]*mock.DataMapper
mappers map[work.TypeName]*mock.UnitDataMapper
mc *gomock.Controller

// metrics scope names and tags.
Expand All @@ -60,14 +60,14 @@ func (s *UnitTestSuite) SetupTest() {

// initialize mocks.
s.mc = gomock.NewController(s.T())
s.mappers = make(map[work.TypeName]*mock.DataMapper)
s.mappers[fooTypeName] = mock.NewDataMapper(s.mc)
s.mappers[barTypeName] = mock.NewDataMapper(s.mc)
s.mappers[bizTypeName] = mock.NewDataMapper(s.mc)
s.mappers[bazTypeName] = mock.NewDataMapper(s.mc)
s.mappers = make(map[work.TypeName]*mock.UnitDataMapper)
s.mappers[fooTypeName] = mock.NewUnitDataMapper(s.mc)
s.mappers[barTypeName] = mock.NewUnitDataMapper(s.mc)
s.mappers[bizTypeName] = mock.NewUnitDataMapper(s.mc)
s.mappers[bazTypeName] = mock.NewUnitDataMapper(s.mc)

// construct SUT.
dm := make(map[work.TypeName]work.DataMapper)
dm := make(map[work.TypeName]work.UnitDataMapper)
for t, m := range s.mappers {
dm[t] = m
}
Expand Down Expand Up @@ -97,7 +97,7 @@ func (s *UnitTestSuite) TestUnit_NewUnit_NoDataMappers() {

// action.
var err error
dm := map[work.TypeName]work.DataMapper{}
dm := map[work.TypeName]work.UnitDataMapper{}
opts := []work.UnitOption{work.UnitDataMappers(dm)}
s.sut, err = work.NewUnit(opts...)

Expand All @@ -123,8 +123,8 @@ func (s *UnitTestSuite) TestUnit_Add_MissingDataMapper() {
entities := []interface{}{
test.Foo{ID: 28},
}
mappers := map[work.TypeName]work.DataMapper{
work.TypeNameOf(test.Bar{}): &mock.DataMapper{},
mappers := map[work.TypeName]work.UnitDataMapper{
work.TypeNameOf(test.Bar{}): &mock.UnitDataMapper{},
}
var err error
opts := []work.UnitOption{work.UnitDataMappers(mappers)}
Expand Down Expand Up @@ -196,8 +196,8 @@ func (s *UnitTestSuite) TestUnit_Alter_MissingDataMapper() {
entities := []interface{}{
test.Foo{ID: 28},
}
mappers := map[work.TypeName]work.DataMapper{
work.TypeNameOf(test.Bar{}): &mock.DataMapper{},
mappers := map[work.TypeName]work.UnitDataMapper{
work.TypeNameOf(test.Bar{}): &mock.UnitDataMapper{},
}
var err error
opts := []work.UnitOption{work.UnitDataMappers(mappers)}
Expand Down Expand Up @@ -269,8 +269,8 @@ func (s *UnitTestSuite) TestUnit_Remove_MissingDataMapper() {
entities := []interface{}{
test.Bar{ID: "28"},
}
mappers := map[work.TypeName]work.DataMapper{
work.TypeNameOf(test.Foo{}): &mock.DataMapper{},
mappers := map[work.TypeName]work.UnitDataMapper{
work.TypeNameOf(test.Foo{}): &mock.UnitDataMapper{},
}
var err error
opts := []work.UnitOption{work.UnitDataMappers(mappers)}
Expand Down Expand Up @@ -342,8 +342,8 @@ func (s *UnitTestSuite) TestUnit_Register_MissingDataMapper() {
entities := []interface{}{
test.Bar{ID: "28"},
}
mappers := map[work.TypeName]work.DataMapper{
work.TypeNameOf(test.Foo{}): &mock.DataMapper{},
mappers := map[work.TypeName]work.UnitDataMapper{
work.TypeNameOf(test.Foo{}): &mock.UnitDataMapper{},
}
var err error
opts := []work.UnitOption{work.UnitDataMappers(mappers)}
Expand Down
10 changes: 5 additions & 5 deletions v4/uniter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type UniterTestSuite struct {
// mocks.
db *sql.DB
_db sqlmock.Sqlmock
mappers map[work.TypeName]*mock.DataMapper
mappers map[work.TypeName]*mock.UnitDataMapper
}

func TestUniterTestSuite(t *testing.T) {
Expand All @@ -51,16 +51,16 @@ func (s *UniterTestSuite) SetupTest() {
barTypeName := work.TypeNameOf(bar)

// initialize mocks.
s.mappers = make(map[work.TypeName]*mock.DataMapper)
s.mappers[fooTypeName] = &mock.DataMapper{}
s.mappers[barTypeName] = &mock.DataMapper{}
s.mappers = make(map[work.TypeName]*mock.UnitDataMapper)
s.mappers[fooTypeName] = &mock.UnitDataMapper{}
s.mappers[barTypeName] = &mock.UnitDataMapper{}

var err error
s.db, s._db, err = sqlmock.New()
s.Require().NoError(err)

// construct SUT.
dm := make(map[work.TypeName]work.DataMapper)
dm := make(map[work.TypeName]work.UnitDataMapper)
for t, m := range s.mappers {
dm[t] = m
}
Expand Down

0 comments on commit 7fee27a

Please sign in to comment.