File: sort_test.go

package info (click to toggle)
golang-github-rubenv-sql-migrate 0.0~git20191213.0633851-2~bpo10+1
  • links: PTS, VCS
  • area: main
  • in suites: buster-backports
  • size: 272 kB
  • sloc: sh: 42; sql: 4; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 1,001 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package migrate

import (
	. "gopkg.in/check.v1"
	"sort"
)

type SortSuite struct{}

var _ = Suite(&SortSuite{})

func (s *SortSuite) TestSortMigrations(c *C) {
	var migrations = byId([]*Migration{
		&Migration{Id: "10_abc", Up: nil, Down: nil},
		&Migration{Id: "120_cde", Up: nil, Down: nil},
		&Migration{Id: "1_abc", Up: nil, Down: nil},
		&Migration{Id: "efg", Up: nil, Down: nil},
		&Migration{Id: "2_cde", Up: nil, Down: nil},
		&Migration{Id: "35_cde", Up: nil, Down: nil},
		&Migration{Id: "3_efg", Up: nil, Down: nil},
		&Migration{Id: "4_abc", Up: nil, Down: nil},
	})

	sort.Sort(migrations)
	c.Assert(migrations, HasLen, 8)
	c.Assert(migrations[0].Id, Equals, "1_abc")
	c.Assert(migrations[1].Id, Equals, "2_cde")
	c.Assert(migrations[2].Id, Equals, "3_efg")
	c.Assert(migrations[3].Id, Equals, "4_abc")
	c.Assert(migrations[4].Id, Equals, "10_abc")
	c.Assert(migrations[5].Id, Equals, "35_cde")
	c.Assert(migrations[6].Id, Equals, "120_cde")
	c.Assert(migrations[7].Id, Equals, "efg")
}