55 "github.com/dipdup-net/go-lib/mocks"
66 "github.com/go-pg/pg/v10"
77 "github.com/golang/mock/gomock"
8+ "github.com/stretchr/testify/assert"
89 "testing"
910)
1011
@@ -30,21 +31,52 @@ func TestMakeCommentsWithTableName(t *testing.T) {
3031 }
3132
3233 mockCtrl , mockPgDB , pgGo , ctx := createPgDbMock (t )
34+ defer mockCtrl .Finish ()
35+
3336 model := Ballot {}
3437
35- // Assert params of ExecContext
38+ // Assert prepare
3639 expectedParams := toInterfaceSlice ([]pg.Safe {"ballots" , "Ballot table" })
3740 mockPgDB .
3841 EXPECT ().
3942 ExecContext (ctx , "COMMENT ON TABLE ? IS ?" ,
4043 gomock .Eq (expectedParams )).
44+ Times (1 ).
4145 Return (nil , nil )
4246
4347 // Act
44- makeComments (ctx , pgGo , model )
48+ err := makeComments (ctx , pgGo , model )
4549
4650 // Assert
51+ assert .Empty (t , err )
52+ }
53+
54+ func TestMakeCommentsWithTableNameWithoutPgComment (t * testing.T ) {
55+ type Ballot struct {
56+ //nolint
57+ tableName struct {} `pg:"ballots"`
58+ Ballot string `json:"ballot"`
59+ }
60+
61+ mockCtrl , mockPgDB , pgGo , ctx := createPgDbMock (t )
4762 defer mockCtrl .Finish ()
63+
64+ model := Ballot {}
65+
66+ // Assert prepare
67+ expectedParams := toInterfaceSlice ([]pg.Safe {"ballots" , "Ballot table" })
68+ mockPgDB .
69+ EXPECT ().
70+ ExecContext (ctx , "COMMENT ON TABLE ? IS ?" ,
71+ gomock .Eq (expectedParams )).
72+ Times (0 ).
73+ Return (nil , nil )
74+
75+ // Act
76+ err := makeComments (ctx , pgGo , model )
77+
78+ // Assert
79+ assert .Empty (t , err )
4880}
4981
5082func createPgDbMock (t * testing.T ) (* gomock.Controller , * mocks.MockPgDB , * PgGoMock , context.Context ) {
0 commit comments