github.com/friesencr/pop/v6@v6.1.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  	examples := Migrations{
    12  		{
    13  			Version: "1",
    14  			DBType:  "all",
    15  		},
    16  		{
    17  			Version: "1",
    18  			DBType:  "postgres",
    19  		},
    20  		{
    21  			Version: "2",
    22  			DBType:  "cockroach",
    23  		},
    24  		{
    25  			Version: "2",
    26  			DBType:  "all",
    27  		},
    28  		{
    29  			Version: "3",
    30  			DBType:  "all",
    31  		},
    32  		{
    33  			Version: "3",
    34  			DBType:  "mysql",
    35  		},
    36  	}
    37  
    38  	t.Run("case=enforces precedence for specific up migrations", func(t *testing.T) {
    39  		migrations := make(Migrations, len(examples))
    40  		copy(migrations, examples)
    41  
    42  		expectedOrder := Migrations{
    43  			examples[1],
    44  			examples[0],
    45  			examples[2],
    46  			examples[3],
    47  			examples[5],
    48  			examples[4],
    49  		}
    50  
    51  		sort.Sort(UpMigrations{migrations})
    52  
    53  		assert.Equal(t, expectedOrder, migrations)
    54  	})
    55  
    56  	t.Run("case=enforces precedence for specific down migrations", func(t *testing.T) {
    57  		migrations := make(Migrations, len(examples))
    58  		copy(migrations, examples)
    59  
    60  		expectedOrder := Migrations{
    61  			examples[5],
    62  			examples[4],
    63  			examples[2],
    64  			examples[3],
    65  			examples[1],
    66  			examples[0],
    67  		}
    68  
    69  		sort.Sort(DownMigrations{migrations})
    70  
    71  		assert.Equal(t, expectedOrder, migrations)
    72  	})
    73  }