@@ -104,13 +104,15 @@ func TestTransactionMode(t *testing.T) {
104104 // reset so we can check the default is set
105105 migration2 .goUp .Mode , migration2 .goDown .Mode = 0 , 0
106106 err = SetGlobalMigrations (migration2 )
107- check .NoError (t , err )
108- check .Number (t , len (registeredGoMigrations ), 2 )
109- registered = registeredGoMigrations [2 ]
110- check .Bool (t , registered .goUp != nil , true )
111- check .Bool (t , registered .goDown != nil , true )
112- check .Equal (t , registered .goUp .Mode , TransactionEnabled )
113- check .Equal (t , registered .goDown .Mode , TransactionEnabled )
107+ check .HasError (t , err )
108+ check .Contains (t , err .Error (), "invalid go migration: up function: invalid mode: 0" )
109+
110+ migration3 := NewGoMigration (3 , nil , nil )
111+ // reset so we can check the default is set
112+ migration3 .goDown .Mode = 0
113+ err = SetGlobalMigrations (migration3 )
114+ check .HasError (t , err )
115+ check .Contains (t , err .Error (), "invalid go migration: down function: invalid mode: 0" )
114116 })
115117 t .Run ("unknown_mode" , func (t * testing.T ) {
116118 m := NewGoMigration (1 , nil , nil )
@@ -192,7 +194,7 @@ func TestGlobalRegister(t *testing.T) {
192194 runTx := func (context.Context , * sql.Tx ) error { return nil }
193195
194196 // Success.
195- err := SetGlobalMigrations ([]Migration {}... )
197+ err := SetGlobalMigrations ([]* Migration {}... )
196198 check .NoError (t , err )
197199 err = SetGlobalMigrations (
198200 NewGoMigration (1 , & GoFunc {RunTx : runTx }, nil ),
@@ -204,62 +206,79 @@ func TestGlobalRegister(t *testing.T) {
204206 )
205207 check .HasError (t , err )
206208 check .Contains (t , err .Error (), "go migration with version 1 already registered" )
207- err = SetGlobalMigrations (Migration {Registered : true , Version : 2 , Type : TypeGo })
209+ err = SetGlobalMigrations (& Migration {Registered : true , Version : 2 , Type : TypeGo })
208210 check .HasError (t , err )
209211 check .Contains (t , err .Error (), "must use NewGoMigration to construct migrations" )
210212}
211213
212214func TestCheckMigration (t * testing.T ) {
215+ // Success.
216+ err := checkGoMigration (NewGoMigration (1 , nil , nil ))
217+ check .NoError (t , err )
213218 // Failures.
214- err := checkMigration (& Migration {})
219+ err = checkGoMigration (& Migration {})
215220 check .HasError (t , err )
216221 check .Contains (t , err .Error (), "must use NewGoMigration to construct migrations" )
217- err = checkMigration (& Migration {construct : true })
222+ err = checkGoMigration (& Migration {construct : true })
218223 check .HasError (t , err )
219224 check .Contains (t , err .Error (), "must be registered" )
220- err = checkMigration (& Migration {construct : true , Registered : true })
225+ err = checkGoMigration (& Migration {construct : true , Registered : true })
221226 check .HasError (t , err )
222227 check .Contains (t , err .Error (), `type must be "go"` )
223- err = checkMigration (& Migration {construct : true , Registered : true , Type : TypeGo })
228+ err = checkGoMigration (& Migration {construct : true , Registered : true , Type : TypeGo })
224229 check .HasError (t , err )
225230 check .Contains (t , err .Error (), "version must be greater than zero" )
231+ err = checkGoMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 1 , goUp : & GoFunc {}, goDown : & GoFunc {}})
232+ check .HasError (t , err )
233+ check .Contains (t , err .Error (), "up function: invalid mode: 0" )
234+ err = checkGoMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 1 , goUp : & GoFunc {Mode : TransactionEnabled }, goDown : & GoFunc {}})
235+ check .HasError (t , err )
236+ check .Contains (t , err .Error (), "down function: invalid mode: 0" )
226237 // Success.
227- err = checkMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 1 })
238+ err = checkGoMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 1 , goUp : & GoFunc { Mode : TransactionEnabled }, goDown : & GoFunc { Mode : TransactionEnabled } })
228239 check .NoError (t , err )
229240 // Failures.
230- err = checkMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 1 , Source : "foo" })
241+ err = checkGoMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 1 , Source : "foo" })
231242 check .HasError (t , err )
232243 check .Contains (t , err .Error (), `source must have .go extension: "foo"` )
233- err = checkMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 1 , Source : "foo.go" })
244+ err = checkGoMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 1 , Source : "foo.go" })
234245 check .HasError (t , err )
235246 check .Contains (t , err .Error (), `no filename separator '_' found` )
236- err = checkMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 2 , Source : "00001_foo.sql" })
247+ err = checkGoMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 2 , Source : "00001_foo.sql" })
237248 check .HasError (t , err )
238249 check .Contains (t , err .Error (), `source must have .go extension: "00001_foo.sql"` )
239- err = checkMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 2 , Source : "00001_foo.go" })
250+ err = checkGoMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 2 , Source : "00001_foo.go" })
240251 check .HasError (t , err )
241252 check .Contains (t , err .Error (), `version:2 does not match numeric component in source "00001_foo.go"` )
242- err = checkMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 1 ,
253+ err = checkGoMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 1 ,
243254 UpFnContext : func (context.Context , * sql.Tx ) error { return nil },
244255 UpFnNoTxContext : func (context.Context , * sql.DB ) error { return nil },
256+ goUp : & GoFunc {Mode : TransactionEnabled },
257+ goDown : & GoFunc {Mode : TransactionEnabled },
245258 })
246259 check .HasError (t , err )
247260 check .Contains (t , err .Error (), "must specify exactly one of UpFnContext or UpFnNoTxContext" )
248- err = checkMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 1 ,
261+ err = checkGoMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 1 ,
249262 DownFnContext : func (context.Context , * sql.Tx ) error { return nil },
250263 DownFnNoTxContext : func (context.Context , * sql.DB ) error { return nil },
264+ goUp : & GoFunc {Mode : TransactionEnabled },
265+ goDown : & GoFunc {Mode : TransactionEnabled },
251266 })
252267 check .HasError (t , err )
253268 check .Contains (t , err .Error (), "must specify exactly one of DownFnContext or DownFnNoTxContext" )
254- err = checkMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 1 ,
269+ err = checkGoMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 1 ,
255270 UpFn : func (* sql.Tx ) error { return nil },
256271 UpFnNoTx : func (* sql.DB ) error { return nil },
272+ goUp : & GoFunc {Mode : TransactionEnabled },
273+ goDown : & GoFunc {Mode : TransactionEnabled },
257274 })
258275 check .HasError (t , err )
259276 check .Contains (t , err .Error (), "must specify exactly one of UpFn or UpFnNoTx" )
260- err = checkMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 1 ,
277+ err = checkGoMigration (& Migration {construct : true , Registered : true , Type : TypeGo , Version : 1 ,
261278 DownFn : func (* sql.Tx ) error { return nil },
262279 DownFnNoTx : func (* sql.DB ) error { return nil },
280+ goUp : & GoFunc {Mode : TransactionEnabled },
281+ goDown : & GoFunc {Mode : TransactionEnabled },
263282 })
264283 check .HasError (t , err )
265284 check .Contains (t , err .Error (), "must specify exactly one of DownFn or DownFnNoTx" )
0 commit comments