Skip to content

Commit b9dbcea

Browse files
committed
Fixed getPgName logic.
1 parent 0f29f19 commit b9dbcea

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

database/pgComment.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,18 @@ func makeComments(ctx context.Context, conn PgGoConnection, model interface{}) e
5858

5959
func getPgName(fieldType reflect.StructField) (name pg.Safe, ok bool) {
6060
pgTag, ok := fieldType.Tag.Lookup("pg")
61-
if ok {
62-
tags := strings.Split(pgTag, ",")
61+
if !ok {
62+
return "", false
63+
}
6364

64-
if tags[0] != "" {
65-
name = pg.Safe(tags[0])
66-
ok = false
67-
}
65+
tags := strings.Split(pgTag, ",")
66+
67+
if tags[0] != "" {
68+
name = pg.Safe(tags[0])
69+
return name, ok
6870
}
6971

70-
return name, ok
72+
return "", false
7173
}
7274

7375
func getPgComment(fieldType reflect.StructField) (pg.Safe, bool) {

database/pgComment_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestMakeCommentsWithTableName(t *testing.T) {
5151
assert.Empty(t, err)
5252
}
5353

54-
func TestMakeCommentsWithTableNameWithoutPgComment(t *testing.T) {
54+
func TestMakeCommentsWithoutPgComment(t *testing.T) {
5555
type Ballot struct {
5656
//nolint
5757
tableName struct{} `pg:"ballots"`
@@ -64,11 +64,15 @@ func TestMakeCommentsWithTableNameWithoutPgComment(t *testing.T) {
6464
model := Ballot{}
6565

6666
// Assert prepare
67-
expectedParams := toInterfaceSlice([]pg.Safe{"ballots", "Ballot table"})
6867
mockPgDB.
6968
EXPECT().
70-
ExecContext(ctx, "COMMENT ON TABLE ? IS ?",
71-
gomock.Eq(expectedParams)).
69+
ExecContext(ctx, "COMMENT ON TABLE ? IS ?", gomock.Any()).
70+
Times(0).
71+
Return(nil, nil)
72+
73+
mockPgDB.
74+
EXPECT().
75+
ExecContext(ctx, "COMMENT ON COLUMN ?.? IS ?", gomock.Any()).
7276
Times(0).
7377
Return(nil, nil)
7478

0 commit comments

Comments
 (0)