github.com/paweljw/pop@v4.13.1+incompatible/match_test.go (about)

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