@@ -2,14 +2,15 @@ package migrate
22
33import (
44 "database/sql"
5+ "io/ioutil"
56 "os"
67
78 _ "github.com/mattn/go-sqlite3"
89 . "gopkg.in/check.v1"
910 "gopkg.in/gorp.v1"
1011)
1112
12- var filename = "/tmp/sql-migrate-sqlite.db"
13+ var testDatabaseFile * os. File
1314var sqliteMigrations = []* Migration {
1415 & Migration {
1516 Id : "123" ,
@@ -31,15 +32,18 @@ type SqliteMigrateSuite struct {
3132var _ = Suite (& SqliteMigrateSuite {})
3233
3334func (s * SqliteMigrateSuite ) SetUpTest (c * C ) {
34- db , err := sql .Open ("sqlite3" , filename )
35+ var err error
36+ testDatabaseFile , err = ioutil .TempFile ("" , "sql-migrate-sqlite" )
37+ c .Assert (err , IsNil )
38+ db , err := sql .Open ("sqlite3" , testDatabaseFile .Name ())
3539 c .Assert (err , IsNil )
3640
3741 s .Db = db
3842 s .DbMap = & gorp.DbMap {Db : db , Dialect : & gorp.SqliteDialect {}}
3943}
4044
4145func (s * SqliteMigrateSuite ) TearDownTest (c * C ) {
42- err := os .Remove (filename )
46+ err := os .Remove (testDatabaseFile . Name () )
4347 c .Assert (err , IsNil )
4448}
4549
@@ -355,3 +359,24 @@ func (s *SqliteMigrateSuite) TestPlanMigrationWithHoles(c *C) {
355359 c .Assert (plannedMigrations [2 ].Migration .Id , Equals , "2" )
356360 c .Assert (plannedMigrations [2 ].Queries [0 ], Equals , down )
357361}
362+
363+ func (s * SqliteMigrateSuite ) TestLess (c * C ) {
364+ c .Assert ((Migration {Id : "1" }).Less (& Migration {Id : "2" }), Equals , true ) // 1 less than 2
365+ c .Assert ((Migration {Id : "2" }).Less (& Migration {Id : "1" }), Equals , false ) // 2 not less than 1
366+ c .Assert ((Migration {Id : "1" }).Less (& Migration {Id : "a" }), Equals , true ) // 1 less than a
367+ c .Assert ((Migration {Id : "a" }).Less (& Migration {Id : "1" }), Equals , false ) // a not less than 1
368+ c .Assert ((Migration {Id : "a" }).Less (& Migration {Id : "a" }), Equals , false ) // a not less than a
369+ c .Assert ((Migration {Id : "1-a" }).Less (& Migration {Id : "1-b" }), Equals , true ) // 1-a less than 1-b
370+ c .Assert ((Migration {Id : "1-b" }).Less (& Migration {Id : "1-a" }), Equals , false ) // 1-b not less than 1-a
371+ c .Assert ((Migration {Id : "1" }).Less (& Migration {Id : "10" }), Equals , true ) // 1 less than 10
372+ c .Assert ((Migration {Id : "10" }).Less (& Migration {Id : "1" }), Equals , false ) // 10 not less than 1
373+ c .Assert ((Migration {Id : "1_foo" }).Less (& Migration {Id : "10_bar" }), Equals , true ) // 1_foo not less than 1
374+ c .Assert ((Migration {Id : "10_bar" }).Less (& Migration {Id : "1_foo" }), Equals , false ) // 10 not less than 1
375+ // 20160126_1100 less than 20160126_1200
376+ c .Assert ((Migration {Id : "20160126_1100" }).
377+ Less (& Migration {Id : "20160126_1200" }), Equals , true )
378+ // 20160126_1200 not less than 20160126_1100
379+ c .Assert ((Migration {Id : "20160126_1200" }).
380+ Less (& Migration {Id : "20160126_1100" }), Equals , false )
381+
382+ }
0 commit comments