aboutsummaryrefslogtreecommitdiffstats
path: root/internal/models/migration_test.go
blob: 7331dc537098d34961bb7f1002d294e39389886b (plain) (blame)
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
35
36
37
38
39
40
41
42
43
44
45
46
package models_test

import (
	"testing"

	"git.eugenetriguba.com/bolt/cli/internal/models"
	"git.eugenetriguba.com/checkmate/check"
)

func TestNewMigration(t *testing.T) {
	m := models.NewMigration(1, "test message")

	check.Equal(t, m.Version, "0001")
	check.Equal(t, m.Message, "test message")
	check.Equal(t, m.Applied, false)

	m = models.NewMigration(100, "test message")

	check.Equal(t, m.Version, "0100")
	check.Equal(t, m.Message, "test message")
	check.Equal(t, m.Applied, false)
}

func TestName(t *testing.T) {
	type test struct {
		migration    *models.Migration
		expectedName string
	}

	testCases := []test{
		// Underscores are used to separate version and message.
		{
			migration:    models.NewMigration(1, "test_message"),
			expectedName: "0001_test_message",
		},
		// Leading/Trailing spaces trimmed, lowercased, and spaces converted to underscores.
		{
			migration:    models.NewMigration(1, "  teST mesSAGE  "),
			expectedName: "0001_test_message",
		},
	}

	for _, tc := range testCases {
		check.Equal(t, tc.migration.Name(), tc.expectedName)
	}
}