github.com/wrgl/wrgl@v0.14.0/pkg/migrate/migrate_test.go (about) 1 package migrate 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestInsertMigration(t *testing.T) { 10 for i, c := range []struct { 11 Slice []migration 12 Migration migration 13 Expected []migration 14 }{ 15 { 16 Migration: migration{ 17 SemVer: &SemVer{}, 18 }, 19 Expected: []migration{ 20 { 21 SemVer: &SemVer{}, 22 }, 23 }, 24 }, 25 { 26 Slice: []migration{ 27 { 28 SemVer: &SemVer{0, 0, 1}, 29 }, 30 }, 31 Migration: migration{ 32 SemVer: &SemVer{0, 1, 0}, 33 }, 34 Expected: []migration{ 35 { 36 SemVer: &SemVer{0, 0, 1}, 37 }, 38 { 39 SemVer: &SemVer{0, 1, 0}, 40 }, 41 }, 42 }, 43 { 44 Slice: []migration{ 45 { 46 SemVer: &SemVer{0, 1, 0}, 47 }, 48 }, 49 Migration: migration{ 50 SemVer: &SemVer{0, 0, 9}, 51 }, 52 Expected: []migration{ 53 { 54 SemVer: &SemVer{0, 0, 9}, 55 }, 56 { 57 SemVer: &SemVer{0, 1, 0}, 58 }, 59 }, 60 }, 61 { 62 Slice: []migration{ 63 { 64 SemVer: &SemVer{0, 1, 0}, 65 }, 66 { 67 SemVer: &SemVer{0, 2, 0}, 68 }, 69 }, 70 Migration: migration{ 71 SemVer: &SemVer{0, 1, 2}, 72 }, 73 Expected: []migration{ 74 { 75 SemVer: &SemVer{0, 1, 0}, 76 }, 77 { 78 SemVer: &SemVer{0, 1, 2}, 79 }, 80 { 81 SemVer: &SemVer{0, 2, 0}, 82 }, 83 }, 84 }, 85 } { 86 assert.Equal(t, c.Expected, insertMigration(c.Slice, c.Migration), "case %d", i) 87 } 88 }