Skip to content

Commit 9c90241

Browse files
authored
Merge pull request #17 from dipdup-io/fix-make-comments-models-validation
2 parents 28e8912 + 8f8357b commit 9c90241

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

database/comment.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ import (
88
)
99

1010
func MakeComments(ctx context.Context, sc SchemeCommenter, models ...interface{}) error {
11+
if models == nil {
12+
return nil
13+
}
14+
1115
for _, model := range models {
16+
if model == nil {
17+
continue
18+
}
19+
1220
modelType := reflect.TypeOf(model)
1321

1422
if reflect.ValueOf(model).Kind() == reflect.Ptr {

database/comment_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,37 @@ func TestMakeCommentsIgnoreFieldsWithEmptyComment(t *testing.T) {
262262
// Assert
263263
assert.Empty(t, err)
264264
}
265+
266+
func TestMakeCommentsIgnoreNilModel(t *testing.T) {
267+
mockCtrl, mockSC, ctx := initMocks(t)
268+
defer mockCtrl.Finish()
269+
270+
// Assert prepare
271+
mockSC.
272+
EXPECT().
273+
MakeColumnComment(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
274+
Times(0)
275+
276+
// Act
277+
err := MakeComments(ctx, mockSC, nil)
278+
279+
// Assert
280+
assert.Empty(t, err)
281+
}
282+
283+
func TestMakeCommentsIgnoreNoModels(t *testing.T) {
284+
mockCtrl, mockSC, ctx := initMocks(t)
285+
defer mockCtrl.Finish()
286+
287+
// Assert prepare
288+
mockSC.
289+
EXPECT().
290+
MakeColumnComment(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
291+
Times(0)
292+
293+
// Act
294+
err := MakeComments(ctx, mockSC)
295+
296+
// Assert
297+
assert.Empty(t, err)
298+
}

0 commit comments

Comments
 (0)