github.com/paweljw/pop/v5@v5.4.6/migration_info_test.go (about)

     1  package pop
     2  
     3  import (
     4  	"sort"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestSortingMigrations(t *testing.T) {
    11  	t.Run("case=enforces precedence for specific migrations", func(t *testing.T) {
    12  		migrations := Migrations{
    13  			{
    14  				Version: "1",
    15  				DBType:  "all",
    16  			},
    17  			{
    18  				Version: "1",
    19  				DBType:  "postgres",
    20  			},
    21  			{
    22  				Version: "2",
    23  				DBType:  "cockroach",
    24  			},
    25  			{
    26  				Version: "2",
    27  				DBType:  "all",
    28  			},
    29  			{
    30  				Version: "3",
    31  				DBType:  "all",
    32  			},
    33  			{
    34  				Version: "3",
    35  				DBType:  "mysql",
    36  			},
    37  		}
    38  		expectedOrder := Migrations{
    39  			migrations[1],
    40  			migrations[0],
    41  			migrations[2],
    42  			migrations[3],
    43  			migrations[5],
    44  			migrations[4],
    45  		}
    46  
    47  		sort.Sort(migrations)
    48  
    49  		assert.Equal(t, expectedOrder, migrations)
    50  	})
    51  }