...

Source file src/github.com/ory/x/popx/migration_info_test.go

Documentation: github.com/ory/x/popx

     1  package popx
     2  
     3  import (
     4  	"sort"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  var migrations = Migrations{
    11  	{
    12  		Version: "1",
    13  		DBType:  "all",
    14  	},
    15  	{
    16  		Version: "1",
    17  		DBType:  "postgres",
    18  	},
    19  	{
    20  		Version: "2",
    21  		DBType:  "cockroach",
    22  	},
    23  	{
    24  		Version: "2",
    25  		DBType:  "all",
    26  	},
    27  	{
    28  		Version: "3",
    29  		DBType:  "all",
    30  	},
    31  	{
    32  		Version: "3",
    33  		DBType:  "mysql",
    34  	},
    35  }
    36  
    37  func TestFilterMigrations(t *testing.T) {
    38  	t.Run("db=mysql", func(t *testing.T) {
    39  		assert.Equal(t, Migrations{
    40  			migrations[0],
    41  			migrations[3],
    42  			migrations[5],
    43  		}, migrations.SortAndFilter("mysql"))
    44  		assert.Equal(t, Migrations{
    45  			migrations[5],
    46  			migrations[3],
    47  			migrations[0],
    48  		}, migrations.SortAndFilter("mysql", sort.Reverse))
    49  	})
    50  }
    51  
    52  func TestSortingMigrations(t *testing.T) {
    53  	t.Run("case=enforces precedence for specific migrations", func(t *testing.T) {
    54  		expectedOrder := Migrations{
    55  			migrations[1],
    56  			migrations[0],
    57  			migrations[2],
    58  			migrations[3],
    59  			migrations[5],
    60  			migrations[4],
    61  		}
    62  
    63  		sort.Sort(migrations)
    64  
    65  		assert.Equal(t, expectedOrder, migrations)
    66  	})
    67  }
    68  

View as plain text