github.com/dkishere/pop/v6@v6.103.1/match_test.go (about) 1 package pop 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 func Test_ParseMigrationFilenameFizzDown(t *testing.T) { 10 r := require.New(t) 11 12 m, err := ParseMigrationFilename("20190611004000_create_providers.down.fizz") 13 r.NoError(err) 14 r.NotNil(m) 15 r.Equal(m.Version, "20190611004000") 16 r.Equal(m.Name, "create_providers") 17 r.Equal(m.DBType, "all") 18 r.Equal(m.Direction, "down") 19 r.Equal(m.Type, "fizz") 20 } 21 22 func Test_ParseMigrationFilenameFizzUp(t *testing.T) { 23 r := require.New(t) 24 25 m, err := ParseMigrationFilename("20190611004000_create_providers.up.fizz") 26 r.NoError(err) 27 r.NotNil(m) 28 r.Equal(m.Version, "20190611004000") 29 r.Equal(m.Name, "create_providers") 30 r.Equal(m.DBType, "all") 31 r.Equal(m.Direction, "up") 32 r.Equal(m.Type, "fizz") 33 } 34 35 func Test_ParseMigrationFilenameFizzUpPostgres(t *testing.T) { 36 r := require.New(t) 37 38 m, err := ParseMigrationFilename("20190611004000_create_providers.pg.up.fizz") 39 r.NotNil(err) 40 r.Equal(err.Error(), "invalid database type \"postgres\", expected \"all\" because fizz is database type independent") 41 r.Nil(m) 42 } 43 44 func Test_ParseMigrationFilenameFizzDownPostgres(t *testing.T) { 45 r := require.New(t) 46 47 m, err := ParseMigrationFilename("20190611004000_create_providers.pg.down.fizz") 48 r.NotNil(err) 49 r.Equal(err.Error(), "invalid database type \"postgres\", expected \"all\" because fizz is database type independent") 50 r.Nil(m) 51 } 52 53 func Test_ParseMigrationFilenameSQLUp(t *testing.T) { 54 r := require.New(t) 55 56 m, err := ParseMigrationFilename("20190611004000_create_providers.up.sql") 57 r.NoError(err) 58 r.NotNil(m) 59 r.Equal(m.Version, "20190611004000") 60 r.Equal(m.Name, "create_providers") 61 r.Equal(m.DBType, "all") 62 r.Equal(m.Direction, "up") 63 r.Equal(m.Type, "sql") 64 } 65 66 func Test_ParseMigrationFilenameSQLUpPostgres(t *testing.T) { 67 r := require.New(t) 68 69 m, err := ParseMigrationFilename("20190611004000_create_providers.pg.up.sql") 70 r.NoError(err) 71 r.NotNil(m) 72 r.Equal(m.Version, "20190611004000") 73 r.Equal(m.Name, "create_providers") 74 r.Equal(m.DBType, "postgres") 75 r.Equal(m.Direction, "up") 76 r.Equal(m.Type, "sql") 77 }