@@ -44,16 +44,9 @@ func TestMultiWithNoRequests(t *testing.T) {
4444 m , _ := mockDatabase (t )
4545 defer m .db .Close ()
4646
47- m .db .ExpectBegin ()
48- m .db .ExpectCommit ()
49- // There's also a rollback called after a commit, which is expected and will not have effect
50- m .db .ExpectRollback ()
51-
52- var operations []state.TransactionalStateOperation
53-
5447 // Act
5548 err := m .pg .Multi (context .Background (), & state.TransactionalStateRequest {
56- Operations : operations ,
49+ Operations : nil ,
5750 })
5851
5952 // Assert
@@ -66,24 +59,46 @@ func TestValidSetRequest(t *testing.T) {
6659 defer m .db .Close ()
6760
6861 setReq := createSetRequest ()
69- operations := []state.TransactionalStateOperation {setReq }
7062 val , _ := json .Marshal (setReq .Value )
7163
72- m .db .ExpectBegin ()
73- m .db .ExpectExec ("INSERT INTO" ).
74- WithArgs (setReq .Key , string (val ), false ).
75- WillReturnResult (pgxmock .NewResult ("INSERT" , 1 ))
76- m .db .ExpectCommit ()
77- // There's also a rollback called after a commit, which is expected and will not have effect
78- m .db .ExpectRollback ()
64+ t .Run ("single op" , func (t * testing.T ) {
65+ operations := []state.TransactionalStateOperation {setReq }
7966
80- // Act
81- err := m .pg .Multi (context .Background (), & state.TransactionalStateRequest {
82- Operations : operations ,
67+ m .db .ExpectExec ("INSERT INTO" ).
68+ WithArgs (setReq .Key , string (val ), false ).
69+ WillReturnResult (pgxmock .NewResult ("INSERT" , 1 ))
70+
71+ // Act
72+ err := m .pg .Multi (context .Background (), & state.TransactionalStateRequest {
73+ Operations : operations ,
74+ })
75+
76+ // Assert
77+ require .NoError (t , err )
8378 })
8479
85- // Assert
86- require .NoError (t , err )
80+ t .Run ("multiple ops" , func (t * testing.T ) {
81+ operations := []state.TransactionalStateOperation {setReq , setReq }
82+
83+ m .db .ExpectBegin ()
84+ m .db .ExpectExec ("INSERT INTO" ).
85+ WithArgs (setReq .Key , string (val ), false ).
86+ WillReturnResult (pgxmock .NewResult ("INSERT" , 1 ))
87+ m .db .ExpectExec ("INSERT INTO" ).
88+ WithArgs (setReq .Key , string (val ), false ).
89+ WillReturnResult (pgxmock .NewResult ("INSERT" , 1 ))
90+ m .db .ExpectCommit ()
91+ // There's also a rollback called after a commit, which is expected and will not have effect
92+ m .db .ExpectRollback ()
93+
94+ // Act
95+ err := m .pg .Multi (context .Background (), & state.TransactionalStateRequest {
96+ Operations : operations ,
97+ })
98+
99+ // Assert
100+ require .NoError (t , err )
101+ })
87102}
88103
89104func TestInvalidMultiSetRequestNoKey (t * testing.T ) {
@@ -113,23 +128,45 @@ func TestValidMultiDeleteRequest(t *testing.T) {
113128 defer m .db .Close ()
114129
115130 deleteReq := createDeleteRequest ()
116- operations := []state.TransactionalStateOperation {deleteReq }
117131
118- m .db .ExpectBegin ()
119- m .db .ExpectExec ("DELETE FROM" ).
120- WithArgs (deleteReq .Key ).
121- WillReturnResult (pgxmock .NewResult ("DELETE" , 1 ))
122- m .db .ExpectCommit ()
123- // There's also a rollback called after a commit, which is expected and will not have effect
124- m .db .ExpectRollback ()
132+ t .Run ("single op" , func (t * testing.T ) {
133+ operations := []state.TransactionalStateOperation {deleteReq }
125134
126- // Act
127- err := m .pg .Multi (context .Background (), & state.TransactionalStateRequest {
128- Operations : operations ,
135+ m .db .ExpectExec ("DELETE FROM" ).
136+ WithArgs (deleteReq .Key ).
137+ WillReturnResult (pgxmock .NewResult ("DELETE" , 1 ))
138+
139+ // Act
140+ err := m .pg .Multi (context .Background (), & state.TransactionalStateRequest {
141+ Operations : operations ,
142+ })
143+
144+ // Assert
145+ require .NoError (t , err )
129146 })
130147
131- // Assert
132- require .NoError (t , err )
148+ t .Run ("multiple ops" , func (t * testing.T ) {
149+ operations := []state.TransactionalStateOperation {deleteReq , deleteReq }
150+
151+ m .db .ExpectBegin ()
152+ m .db .ExpectExec ("DELETE FROM" ).
153+ WithArgs (deleteReq .Key ).
154+ WillReturnResult (pgxmock .NewResult ("DELETE" , 1 ))
155+ m .db .ExpectExec ("DELETE FROM" ).
156+ WithArgs (deleteReq .Key ).
157+ WillReturnResult (pgxmock .NewResult ("DELETE" , 1 ))
158+ m .db .ExpectCommit ()
159+ // There's also a rollback called after a commit, which is expected and will not have effect
160+ m .db .ExpectRollback ()
161+
162+ // Act
163+ err := m .pg .Multi (context .Background (), & state.TransactionalStateRequest {
164+ Operations : operations ,
165+ })
166+
167+ // Assert
168+ require .NoError (t , err )
169+ })
133170}
134171
135172func TestInvalidMultiDeleteRequestNoKey (t * testing.T ) {
@@ -140,7 +177,7 @@ func TestInvalidMultiDeleteRequestNoKey(t *testing.T) {
140177 m .db .ExpectBegin ()
141178 m .db .ExpectRollback ()
142179
143- operations := []state.TransactionalStateOperation {state.DeleteRequest {}} // Delete request without key is not valid for Delete operation
180+ operations := []state.TransactionalStateOperation {state.DeleteRequest {}, state. DeleteRequest {} } // Delete request without key is not valid for Delete operation
144181
145182 // Act
146183 err := m .pg .Multi (context .Background (), & state.TransactionalStateRequest {
0 commit comments