Skip to content

Commit 00a6445

Browse files
export the interfaces (#64)
1 parent 22f577f commit 00a6445

File tree

15 files changed

+173
-173
lines changed

15 files changed

+173
-173
lines changed

aggregator/aggregator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import (
2222
)
2323

2424
//go:generate mockgen -source=aggregator.go -destination=../mock/aggregator.mock.go -package=mocks
25-
type iAggregator[T any] interface {
25+
type IAggregator[T any] interface {
2626
Aggregate(ctx context.Context, opts ...options.Lister[options.AggregateOptions]) ([]*T, error)
2727
AggregateWithParse(ctx context.Context, result any, opts ...options.Lister[options.AggregateOptions]) error
2828
}
2929

30-
var _ iAggregator[any] = (*Aggregator[any])(nil)
30+
var _ IAggregator[any] = (*Aggregator[any])(nil)
3131

3232
type Aggregator[T any] struct {
3333
collection *mongo.Collection

aggregator/aggregator_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ func TestAggregator_New(t *testing.T) {
8080
func TestAggregator_Aggregation(t *testing.T) {
8181
testCases := []struct {
8282
name string
83-
mock func(ctx context.Context, ctl *gomock.Controller) iAggregator[TestUser]
83+
mock func(ctx context.Context, ctl *gomock.Controller) IAggregator[TestUser]
8484
ctx context.Context
8585
want []*TestUser
8686
wantErr assert.ErrorAssertionFunc
8787
}{
8888
{
8989
name: "got error",
90-
mock: func(ctx context.Context, ctl *gomock.Controller) iAggregator[TestUser] {
91-
aggregator := mocks.NewMockiAggregator[TestUser](ctl)
90+
mock: func(ctx context.Context, ctl *gomock.Controller) IAggregator[TestUser] {
91+
aggregator := mocks.NewMockIAggregator[TestUser](ctl)
9292
aggregator.EXPECT().Aggregate(ctx).Return(nil, errors.New("can only marshal slices and arrays into aggregation pipelines, but got invalid")).Times(1)
9393
return aggregator
9494
},
@@ -97,8 +97,8 @@ func TestAggregator_Aggregation(t *testing.T) {
9797
},
9898
{
9999
name: "got result",
100-
mock: func(ctx context.Context, ctl *gomock.Controller) iAggregator[TestUser] {
101-
aggregator := mocks.NewMockiAggregator[TestUser](ctl)
100+
mock: func(ctx context.Context, ctl *gomock.Controller) IAggregator[TestUser] {
101+
aggregator := mocks.NewMockIAggregator[TestUser](ctl)
102102
aggregator.EXPECT().Aggregate(ctx).Return([]*TestUser{
103103
{Name: "chenmingyong", Age: 24},
104104
{Name: "gopher", Age: 25},
@@ -136,16 +136,16 @@ func TestAggregator_AggregateWithParse(t *testing.T) {
136136
}
137137
testCases := []struct {
138138
name string
139-
mock func(ctx context.Context, ctl *gomock.Controller, result any) iAggregator[TestUser]
139+
mock func(ctx context.Context, ctl *gomock.Controller, result any) IAggregator[TestUser]
140140
ctx context.Context
141141
result []*User
142142
want []*User
143143
wantErr assert.ErrorAssertionFunc
144144
}{
145145
{
146146
name: "got error",
147-
mock: func(ctx context.Context, ctl *gomock.Controller, result any) iAggregator[TestUser] {
148-
aggregator := mocks.NewMockiAggregator[TestUser](ctl)
147+
mock: func(ctx context.Context, ctl *gomock.Controller, result any) IAggregator[TestUser] {
148+
aggregator := mocks.NewMockIAggregator[TestUser](ctl)
149149
aggregator.EXPECT().AggregateWithParse(ctx, result).Return(errors.New("can only marshal slices and arrays into aggregation pipelines, but got invalid")).Times(1)
150150
return aggregator
151151
},
@@ -155,8 +155,8 @@ func TestAggregator_AggregateWithParse(t *testing.T) {
155155
},
156156
{
157157
name: "got result",
158-
mock: func(ctx context.Context, ctl *gomock.Controller, result any) iAggregator[TestUser] {
159-
aggregator := mocks.NewMockiAggregator[TestUser](ctl)
158+
mock: func(ctx context.Context, ctl *gomock.Controller, result any) IAggregator[TestUser] {
159+
aggregator := mocks.NewMockIAggregator[TestUser](ctl)
160160
aggregator.EXPECT().AggregateWithParse(ctx, result).Return(nil).Times(1)
161161
return aggregator
162162
},

creator/creator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ import (
2727
)
2828

2929
//go:generate mockgen -source=creator.go -destination=../mock/creator.mock.go -package=mocks
30-
type iCreator[T any] interface {
30+
type ICreator[T any] interface {
3131
InsertOne(ctx context.Context, docs *T, opts ...options.Lister[options.InsertOneOptions]) (*mongo.InsertOneResult, error)
3232
InsertMany(ctx context.Context, docs []*T, opts ...options.Lister[options.InsertManyOptions]) (*mongo.InsertManyResult, error)
3333
}
3434

35-
var _ iCreator[any] = (*Creator[any])(nil)
35+
var _ ICreator[any] = (*Creator[any])(nil)
3636

3737
type Creator[T any] struct {
3838
collection *mongo.Collection

creator/creator_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ func TestNewCreator(t *testing.T) {
5858
func TestCreator_One(t *testing.T) {
5959
testCases := []struct {
6060
name string
61-
mock func(ctx context.Context, ctl *gomock.Controller, doc *TestUser) iCreator[TestUser]
61+
mock func(ctx context.Context, ctl *gomock.Controller, doc *TestUser) ICreator[TestUser]
6262
ctx context.Context
6363
doc *TestUser
6464

6565
wantErr error
6666
}{
6767
{
6868
name: "nil doc",
69-
mock: func(ctx context.Context, ctl *gomock.Controller, doc *TestUser) iCreator[TestUser] {
70-
mockCollection := mocks.NewMockiCreator[TestUser](ctl)
69+
mock: func(ctx context.Context, ctl *gomock.Controller, doc *TestUser) ICreator[TestUser] {
70+
mockCollection := mocks.NewMockICreator[TestUser](ctl)
7171
mockCollection.EXPECT().InsertOne(ctx, doc).Return(nil, errors.New("nil filter")).Times(1)
7272
return mockCollection
7373
},
@@ -77,8 +77,8 @@ func TestCreator_One(t *testing.T) {
7777
},
7878
{
7979
name: "success",
80-
mock: func(ctx context.Context, ctl *gomock.Controller, doc *TestUser) iCreator[TestUser] {
81-
mockCollection := mocks.NewMockiCreator[TestUser](ctl)
80+
mock: func(ctx context.Context, ctl *gomock.Controller, doc *TestUser) ICreator[TestUser] {
81+
mockCollection := mocks.NewMockICreator[TestUser](ctl)
8282
mockCollection.EXPECT().InsertOne(ctx, doc).Return(&mongo.InsertOneResult{InsertedID: "?"}, nil).Times(1)
8383
return mockCollection
8484
},
@@ -107,7 +107,7 @@ func TestCreator_One(t *testing.T) {
107107
func TestCreator_Many(t *testing.T) {
108108
testCases := []struct {
109109
name string
110-
mock func(ctx context.Context, ctl *gomock.Controller, docs []*TestUser) iCreator[TestUser]
110+
mock func(ctx context.Context, ctl *gomock.Controller, docs []*TestUser) ICreator[TestUser]
111111
ctx context.Context
112112
docs []*TestUser
113113

@@ -116,8 +116,8 @@ func TestCreator_Many(t *testing.T) {
116116
}{
117117
{
118118
name: "nil docs",
119-
mock: func(ctx context.Context, ctl *gomock.Controller, docs []*TestUser) iCreator[TestUser] {
120-
mockCollection := mocks.NewMockiCreator[TestUser](ctl)
119+
mock: func(ctx context.Context, ctl *gomock.Controller, docs []*TestUser) ICreator[TestUser] {
120+
mockCollection := mocks.NewMockICreator[TestUser](ctl)
121121
mockCollection.EXPECT().InsertMany(ctx, docs).Return(nil, errors.New("nil docs")).Times(1)
122122
return mockCollection
123123
},
@@ -130,8 +130,8 @@ func TestCreator_Many(t *testing.T) {
130130
},
131131
{
132132
name: "success",
133-
mock: func(ctx context.Context, ctl *gomock.Controller, docs []*TestUser) iCreator[TestUser] {
134-
mockCollection := mocks.NewMockiCreator[TestUser](ctl)
133+
mock: func(ctx context.Context, ctl *gomock.Controller, docs []*TestUser) ICreator[TestUser] {
134+
mockCollection := mocks.NewMockICreator[TestUser](ctl)
135135
mockCollection.EXPECT().InsertMany(ctx, docs).Return(&mongo.InsertManyResult{InsertedIDs: make([]interface{}, 2)}, nil).Times(1)
136136
return mockCollection
137137
},

deleter/deleter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ import (
2525
)
2626

2727
//go:generate mockgen -source=deleter.go -destination=../mock/deleter.mock.go -package=mocks
28-
type iDeleter[T any] interface {
28+
type IDeleter[T any] interface {
2929
DeleteOne(ctx context.Context, opts ...options.Lister[options.DeleteOptions]) (*mongo.DeleteResult, error)
3030
DeleteMany(ctx context.Context, opts ...options.Lister[options.DeleteOptions]) (*mongo.DeleteResult, error)
3131
}
3232

33-
var _ iDeleter[any] = (*Deleter[any])(nil)
33+
var _ IDeleter[any] = (*Deleter[any])(nil)
3434

3535
func NewDeleter[T any](collection *mongo.Collection) *Deleter[T] {
3636
return &Deleter[T]{collection: collection, filter: nil}

deleter/deleter_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ func TestDeleter_DeleteOne(t *testing.T) {
5959
testCases := []struct {
6060
name string
6161

62-
mock func(ctx context.Context, ctl *gomock.Controller) iDeleter[TestUser]
62+
mock func(ctx context.Context, ctl *gomock.Controller) IDeleter[TestUser]
6363
ctx context.Context
6464

6565
want *mongo.DeleteResult
6666
wantErr assert.ErrorAssertionFunc
6767
}{
6868
{
6969
name: "error: nil filter",
70-
mock: func(ctx context.Context, ctl *gomock.Controller) iDeleter[TestUser] {
71-
mockCollection := mocks.NewMockiDeleter[TestUser](ctl)
70+
mock: func(ctx context.Context, ctl *gomock.Controller) IDeleter[TestUser] {
71+
mockCollection := mocks.NewMockIDeleter[TestUser](ctl)
7272
mockCollection.EXPECT().DeleteOne(ctx).Return(nil, errors.New("nil filter")).Times(1)
7373
return mockCollection
7474
},
@@ -79,8 +79,8 @@ func TestDeleter_DeleteOne(t *testing.T) {
7979
},
8080
{
8181
name: "deleted count: 0",
82-
mock: func(ctx context.Context, ctl *gomock.Controller) iDeleter[TestUser] {
83-
mockCollection := mocks.NewMockiDeleter[TestUser](ctl)
82+
mock: func(ctx context.Context, ctl *gomock.Controller) IDeleter[TestUser] {
83+
mockCollection := mocks.NewMockIDeleter[TestUser](ctl)
8484
mockCollection.EXPECT().DeleteOne(ctx).Return(&mongo.DeleteResult{DeletedCount: 0}, nil).Times(1)
8585
return mockCollection
8686
},
@@ -92,8 +92,8 @@ func TestDeleter_DeleteOne(t *testing.T) {
9292
},
9393
{
9494
name: "delete success",
95-
mock: func(ctx context.Context, ctl *gomock.Controller) iDeleter[TestUser] {
96-
mockCollection := mocks.NewMockiDeleter[TestUser](ctl)
95+
mock: func(ctx context.Context, ctl *gomock.Controller) IDeleter[TestUser] {
96+
mockCollection := mocks.NewMockIDeleter[TestUser](ctl)
9797
mockCollection.EXPECT().DeleteOne(ctx).Return(&mongo.DeleteResult{DeletedCount: 1}, nil).Times(1)
9898
return mockCollection
9999
},
@@ -124,16 +124,16 @@ func TestDeleter_DeleteMany(t *testing.T) {
124124
testCases := []struct {
125125
name string
126126

127-
mock func(ctx context.Context, ctl *gomock.Controller) iDeleter[TestUser]
127+
mock func(ctx context.Context, ctl *gomock.Controller) IDeleter[TestUser]
128128
ctx context.Context
129129

130130
want *mongo.DeleteResult
131131
wantErr assert.ErrorAssertionFunc
132132
}{
133133
{
134134
name: "error: nil filter",
135-
mock: func(ctx context.Context, ctl *gomock.Controller) iDeleter[TestUser] {
136-
mockCollection := mocks.NewMockiDeleter[TestUser](ctl)
135+
mock: func(ctx context.Context, ctl *gomock.Controller) IDeleter[TestUser] {
136+
mockCollection := mocks.NewMockIDeleter[TestUser](ctl)
137137
mockCollection.EXPECT().DeleteMany(ctx).Return(nil, errors.New("nil filter")).Times(1)
138138
return mockCollection
139139
},
@@ -144,8 +144,8 @@ func TestDeleter_DeleteMany(t *testing.T) {
144144
},
145145
{
146146
name: "deleted count: 0",
147-
mock: func(ctx context.Context, ctl *gomock.Controller) iDeleter[TestUser] {
148-
mockCollection := mocks.NewMockiDeleter[TestUser](ctl)
147+
mock: func(ctx context.Context, ctl *gomock.Controller) IDeleter[TestUser] {
148+
mockCollection := mocks.NewMockIDeleter[TestUser](ctl)
149149
mockCollection.EXPECT().DeleteMany(ctx).Return(&mongo.DeleteResult{DeletedCount: 0}, nil).Times(1)
150150
return mockCollection
151151
},
@@ -157,8 +157,8 @@ func TestDeleter_DeleteMany(t *testing.T) {
157157
},
158158
{
159159
name: "delete success",
160-
mock: func(ctx context.Context, ctl *gomock.Controller) iDeleter[TestUser] {
161-
mockCollection := mocks.NewMockiDeleter[TestUser](ctl)
160+
mock: func(ctx context.Context, ctl *gomock.Controller) IDeleter[TestUser] {
161+
mockCollection := mocks.NewMockIDeleter[TestUser](ctl)
162162
mockCollection.EXPECT().DeleteMany(ctx).Return(&mongo.DeleteResult{DeletedCount: 2}, nil).Times(1)
163163
return mockCollection
164164
},

finder/finder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
//go:generate mockgen -source=finder.go -destination=../mock/finder.mock.go -package=mocks
29-
type iFinder[T any] interface {
29+
type IFinder[T any] interface {
3030
FindOne(ctx context.Context, opts ...options.Lister[options.FindOneOptions]) (*T, error)
3131
Find(ctx context.Context, opts ...options.Lister[options.FindOptions]) ([]*T, error)
3232
Count(ctx context.Context, opts ...options.Lister[options.CountOptions]) (int64, error)
@@ -36,7 +36,7 @@ func NewFinder[T any](collection *mongo.Collection) *Finder[T] {
3636
return &Finder[T]{collection: collection, filter: bson.D{}}
3737
}
3838

39-
var _ iFinder[any] = (*Finder[any])(nil)
39+
var _ IFinder[any] = (*Finder[any])(nil)
4040

4141
type Finder[T any] struct {
4242
collection *mongo.Collection

finder/finder_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,25 @@ func TestFinder_New(t *testing.T) {
3737
func TestFinder_One(t *testing.T) {
3838
testCases := []struct {
3939
name string
40-
mock func(ctx context.Context, ctl *gomock.Controller) iFinder[TestUser]
40+
mock func(ctx context.Context, ctl *gomock.Controller) IFinder[TestUser]
4141
ctx context.Context
4242

4343
want *TestUser
4444
wantErr error
4545
}{
4646
{
4747
name: "error",
48-
mock: func(ctx context.Context, ctl *gomock.Controller) iFinder[TestUser] {
49-
mockCollection := mocks.NewMockiFinder[TestUser](ctl)
48+
mock: func(ctx context.Context, ctl *gomock.Controller) IFinder[TestUser] {
49+
mockCollection := mocks.NewMockIFinder[TestUser](ctl)
5050
mockCollection.EXPECT().FindOne(gomock.Any()).Return(nil, mongo.ErrNoDocuments).Times(1)
5151
return mockCollection
5252
},
5353
wantErr: mongo.ErrNoDocuments,
5454
},
5555
{
5656
name: "match the first one",
57-
mock: func(ctx context.Context, ctl *gomock.Controller) iFinder[TestUser] {
58-
mockCollection := mocks.NewMockiFinder[TestUser](ctl)
57+
mock: func(ctx context.Context, ctl *gomock.Controller) IFinder[TestUser] {
58+
mockCollection := mocks.NewMockIFinder[TestUser](ctl)
5959
mockCollection.EXPECT().FindOne(gomock.Any()).Return(&TestUser{
6060
Name: "chenmingyong",
6161
Age: 24,
@@ -84,25 +84,25 @@ func TestFinder_One(t *testing.T) {
8484
func TestFinder_All(t *testing.T) {
8585
testCases := []struct {
8686
name string
87-
mock func(ctx context.Context, ctl *gomock.Controller) iFinder[TestUser]
87+
mock func(ctx context.Context, ctl *gomock.Controller) IFinder[TestUser]
8888
ctx context.Context
8989

9090
want []*TestUser
9191
wantErr error
9292
}{
9393
{
9494
name: "empty documents",
95-
mock: func(ctx context.Context, ctl *gomock.Controller) iFinder[TestUser] {
96-
mockCollection := mocks.NewMockiFinder[TestUser](ctl)
95+
mock: func(ctx context.Context, ctl *gomock.Controller) IFinder[TestUser] {
96+
mockCollection := mocks.NewMockIFinder[TestUser](ctl)
9797
mockCollection.EXPECT().Find(ctx).Return([]*TestUser{}, nil).Times(1)
9898
return mockCollection
9999
},
100100
want: []*TestUser{},
101101
},
102102
{
103103
name: "matched",
104-
mock: func(ctx context.Context, ctl *gomock.Controller) iFinder[TestUser] {
105-
mockCollection := mocks.NewMockiFinder[TestUser](ctl)
104+
mock: func(ctx context.Context, ctl *gomock.Controller) IFinder[TestUser] {
105+
mockCollection := mocks.NewMockIFinder[TestUser](ctl)
106106
mockCollection.EXPECT().Find(ctx).Return([]*TestUser{
107107
{
108108
Name: "chenmingyong",
@@ -143,16 +143,16 @@ func TestFinder_All(t *testing.T) {
143143
func TestFinder_Count(t *testing.T) {
144144
testCases := []struct {
145145
name string
146-
mock func(ctx context.Context, ctl *gomock.Controller) iFinder[TestUser]
146+
mock func(ctx context.Context, ctl *gomock.Controller) IFinder[TestUser]
147147
ctx context.Context
148148

149149
want int64
150150
wantErr error
151151
}{
152152
{
153153
name: "error",
154-
mock: func(ctx context.Context, ctl *gomock.Controller) iFinder[TestUser] {
155-
mockCollection := mocks.NewMockiFinder[TestUser](ctl)
154+
mock: func(ctx context.Context, ctl *gomock.Controller) IFinder[TestUser] {
155+
mockCollection := mocks.NewMockIFinder[TestUser](ctl)
156156
mockCollection.EXPECT().Count(ctx).Return(int64(0), errors.New("nil filter error")).Times(1)
157157
return mockCollection
158158
},
@@ -161,17 +161,17 @@ func TestFinder_Count(t *testing.T) {
161161
},
162162
{
163163
name: "matched 0",
164-
mock: func(ctx context.Context, ctl *gomock.Controller) iFinder[TestUser] {
165-
mockCollection := mocks.NewMockiFinder[TestUser](ctl)
164+
mock: func(ctx context.Context, ctl *gomock.Controller) IFinder[TestUser] {
165+
mockCollection := mocks.NewMockIFinder[TestUser](ctl)
166166
mockCollection.EXPECT().Count(ctx).Return(int64(0), nil).Times(1)
167167
return mockCollection
168168
},
169169
want: 0,
170170
},
171171
{
172172
name: "matched 1",
173-
mock: func(ctx context.Context, ctl *gomock.Controller) iFinder[TestUser] {
174-
mockCollection := mocks.NewMockiFinder[TestUser](ctl)
173+
mock: func(ctx context.Context, ctl *gomock.Controller) IFinder[TestUser] {
174+
mockCollection := mocks.NewMockIFinder[TestUser](ctl)
175175
mockCollection.EXPECT().Count(ctx).Return(int64(1), nil).Times(1)
176176
return mockCollection
177177
},

0 commit comments

Comments
 (0)